Use Cases For Stateful and Singleton Adapters [message #557091] |
Sat, 04 September 2010 07:25 |
Animesh Kumar Messages: 18 Registered: September 2010 Location: Bangalore |
Junior Member |
|
|
Hi,
I am new to EMF and was reading about different patterns of Adapters,
i.e., Stateful and Singleton Adapters. I understood there definitions something like this:-
1.Stateful adapters - every object in a model has a one-to-one correspondence with its adapter. One adapter is created for each object. This pattern doubles the number of objects in the application, and the instances are needed to carry additional state.
2.Singleton adapters - use a single adapter for all the items of the same type(or for one class). State is not saved.
I wanted to know what are the different use cases in which we can use stateful adapters and where it is required to use singleton or stateless adapters. I need some examples such that it can clearly differentiate between them.
Regards,
Animesh
|
|
|
Re: Use Cases For Stateful and Singleton Adapters [message #557108 is a reply to message #557091] |
Sat, 04 September 2010 14:15 |
Ed Merks Messages: 33113 Registered: July 2009 |
Senior Member |
|
|
Animesh,
Comments below.
Animesh Kumar wrote:
> Hi,
> I am new to EMF and was reading about different patterns of Adapters,
> i.e., Stateful and Singleton Adapters. I understood there definitions
> something like this:-
> 1.Stateful adapters - every object in a model has a one-to-one
> correspondence with its adapter. One adapter is created for each
> object. This pattern doubles the number of objects in the application,
> and the instances are needed to carry additional state. 2.Singleton
> adapters - use a single adapter for all the items of the same type(or
> for one class). State is not saved.
> I wanted to know what are the different use cases in which we can use
> stateful adapters and where it is required to use singleton or
> stateless adapters. I need some examples such that it can clearly
> differentiate between them.
It's never required to use singletons. It's good to use them when
possible. It's possible when all the adapters methods produce results
that depends only on the arguments passed to them, i.e., when there is
no need to cache or retain information that must be different for each
thing being adapters. When there are no fields, you know you can use a
singleton. If there are fields that cache information, you might still
be able to use a singleton, if for example, that state depends only on
the type of the object, not on the instance data on the object, and you
have a singleton per type (as we do for the generated item providers).
My advice would be, start with a singleton, and when that doesn't work,
you'll notice and need to switch to using stateful ones.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05728 seconds