SessionSingletonBase encapsulated [message #40393] |
Tue, 24 July 2007 05:24  |
Eclipse User |
|
|
|
Originally posted by: pfischer06.fast-mail.org
Hello,
I try to use rap and rcp parallel created from the same ui-code. With
factory-interfaces this works until now. But I want to have an
ApplicationContext as singleton. On rap-side I have to use the abstract
SessionSingletonBase. But this can not be encapsulated to an interface
so I dont know how to have the same static getInstance() acces to a
singleton object on rap and rcp.
Has anyone solved this problem?
Thanks and regards,
Peter
|
|
|
|
|
Re: SessionSingletonBase encapsulated [message #107034 is a reply to message #40547] |
Tue, 30 September 2008 06:59   |
Eclipse User |
|
|
|
Hi Frank,
how can i you your example for this class?
public abstract class MyComposite extends Composite{
protected MyComposite(Composite parent, int style) {
super(parent, style);
createLayout();
init();
}
protected abstract void createLayout();
protected abstract void init();
}
I don't get it on my own! Please help me.
Roland
Frank Appel schrieb:
> Hi,
>
> just a sketch how it could be done, don't say that thats the one-and-only
> way...
>
> The Idea is not to use a classical Singleton approach with only one class. I
> combine it with a kind of factory that is used in the singleton to get the
> singleton implementation of choice. To do this I use to Interfaces:
>
> public interface IMySingleton {
>
> }
>
> public interface IMySingletonFactory {
> IMySingleton getInstance();
> }
>
> One for the actual singleton type and one for the factory that creates the
> instance. The singleton class itself has the expected getInstance() plus a
> register method with which the appropriate factory could be registered. This
> must be done before the first call to getInstance() of course:
>
> public class MySingleton implements IMySingleton {
>
>
> private static IMySingletonFactory factory;
>
> public static void register( final IMySingletonFactory factory ) {
> MySingleton.factory = factory;
> }
>
> public static IMySingleton getInstance() {
> return factory.getInstance();
> }
> }
>
> At last you need the implementations. This can be done somehow like the
> following. As there is not much to do for the factory one can also combine
> the implementation of the factory and the interface type in one class as
> shown with the 'real singleton':
>
> class MySessionSingletonFactoryImpl implements IMySingletonFactory{
>
> public IMySingleton getInstance() {
> return MySessionSingletonImpl.getInstance();
> }
>
> }
> class MySessionSingletonImpl
> extends SessionSingletonBase
> implements IMySingleton
> {
> public static IMySingleton getInstance() {
> return ( IMySingleton )getInstance( MySessionSingletonImpl.class );
> }
> }
>
> class MyRealSingleton
> implements IMySingleton, IMySingletonFactory
> {
> public IMySingleton getInstance() {
> [...]
> }
>
> Hope that helps!
>
> Ciao
> Frank
>
>
> "Peter Fischer" <pfischer06@fast-mail.org> schrieb im Newsbeitrag
> news:f84gfj$85o$1@build.eclipse.org...
>> Hello,
>>
>> I try to use rap and rcp parallel created from the same ui-code. With
>> factory-interfaces this works until now. But I want to have an
>> ApplicationContext as singleton. On rap-side I have to use the abstract
>> SessionSingletonBase. But this can not be encapsulated to an interface so
>> I dont know how to have the same static getInstance() acces to a singleton
>> object on rap and rcp.
>>
>> Has anyone solved this problem?
>>
>> Thanks and regards,
>> Peter
>
>
> Hi,
>
> just a sketch how it could be done, don't say that thats the one-and-only
> way...
>
> The Idea is not to use a classical Singleton approach with only one class. I
> combine it with a kind of factory that is used in the singleton to get the
> singleton implementation of choice. To do this I use to Interfaces:
>
> public interface IMySingleton {
>
> }
>
> public interface IMySingletonFactory {
> IMySingleton getInstance();
> }
>
> One for the actual singleton type and one for the factory that creates the
> instance. The singleton class itself has the expected getInstance() plus a
> register method with which the appropriate factory could be registered. This
> must be done before the first call to getInstance() of course:
>
> public class MySingleton implements IMySingleton {
>
>
> private static IMySingletonFactory factory;
>
> public static void register( final IMySingletonFactory factory ) {
> MySingleton.factory = factory;
> }
>
> public static IMySingleton getInstance() {
> return factory.getInstance();
> }
> }
>
> At last you need the implementations. This can be done somehow like the
> following. As there is not much to do for the factory one can also combine
> the implementation of the factory and the interface type in one class as
> shown with the 'real singleton':
>
> class MySessionSingletonFactoryImpl implements IMySingletonFactory{
>
> public IMySingleton getInstance() {
> return MySessionSingletonImpl.getInstance();
> }
>
> }
> class MySessionSingletonImpl
> extends SessionSingletonBase
> implements IMySingleton
> {
> public static IMySingleton getInstance() {
> return ( IMySingleton )getInstance( MySessionSingletonImpl.class );
> }
> }
>
> class MyRealSingleton
> implements IMySingleton, IMySingletonFactory
> {
> public IMySingleton getInstance() {
> [...]
> }
>
> Hope that helps!
>
> Ciao
> Frank
>
>
> "Peter Fischer" <pfischer06@fast-mail.org> schrieb im Newsbeitrag
> news:f84gfj$85o$1@build.eclipse.org...
>> Hello,
>>
>> I try to use rap and rcp parallel created from the same ui-code. With
>> factory-interfaces this works until now. But I want to have an
>> ApplicationContext as singleton. On rap-side I have to use the abstract
>> SessionSingletonBase. But this can not be encapsulated to an interface so
>> I dont know how to have the same static getInstance() acces to a singleton
>> object on rap and rcp.
>>
>> Has anyone solved this problem?
>>
>> Thanks and regards,
>> Peter
>
>
|
|
|
Re: SessionSingletonBase encapsulated [message #107054 is a reply to message #107034] |
Tue, 30 September 2008 08:17   |
Eclipse User |
|
|
|
Originally posted by: benjamin.wolff.web.de
hi,
the question is, why do you want a composite to be a session-singleton? RAP
handles the session related stuff when using GUI stuff.
do you maybe just want to encapsulate session unique data/handlers/etc.?!
greets
-ben
Roland Siebert schrieb:
> Hi Frank,
>
> how can i you your example for this class?
>
> public abstract class MyComposite extends Composite{
>
> protected MyComposite(Composite parent, int style) {
> super(parent, style);
> createLayout();
> init();
> }
>
> protected abstract void createLayout();
>
> protected abstract void init();
> }
>
> I don't get it on my own! Please help me.
>
> Roland
>
> Frank Appel schrieb:
>> Hi,
>>
>> just a sketch how it could be done, don't say that thats the
>> one-and-only way...
>>
>> The Idea is not to use a classical Singleton approach with only one
>> class. I combine it with a kind of factory that is used in the
>> singleton to get the singleton implementation of choice. To do this I
>> use to Interfaces:
>>
>> public interface IMySingleton {
>>
>> }
>>
>> public interface IMySingletonFactory {
>> IMySingleton getInstance();
>> }
>>
>> One for the actual singleton type and one for the factory that creates
>> the instance. The singleton class itself has the expected
>> getInstance() plus a register method with which the appropriate
>> factory could be registered. This must be done before the first call
>> to getInstance() of course:
>>
>> public class MySingleton implements IMySingleton {
>>
>>
>> private static IMySingletonFactory factory;
>>
>> public static void register( final IMySingletonFactory factory ) {
>> MySingleton.factory = factory;
>> }
>>
>> public static IMySingleton getInstance() {
>> return factory.getInstance();
>> }
>> }
>>
>> At last you need the implementations. This can be done somehow like
>> the following. As there is not much to do for the factory one can also
>> combine the implementation of the factory and the interface type in
>> one class as shown with the 'real singleton':
>>
>> class MySessionSingletonFactoryImpl implements IMySingletonFactory{
>>
>> public IMySingleton getInstance() {
>> return MySessionSingletonImpl.getInstance();
>> }
>>
>> }
>> class MySessionSingletonImpl
>> extends SessionSingletonBase
>> implements IMySingleton
>> {
>> public static IMySingleton getInstance() {
>> return ( IMySingleton )getInstance( MySessionSingletonImpl.class );
>> }
>> }
>>
>> class MyRealSingleton
>> implements IMySingleton, IMySingletonFactory
>> {
>> public IMySingleton getInstance() {
>> [...]
>> }
>>
>> Hope that helps!
>>
>> Ciao
>> Frank
>>
>>
>> "Peter Fischer" <pfischer06@fast-mail.org> schrieb im Newsbeitrag
>> news:f84gfj$85o$1@build.eclipse.org...
>>> Hello,
>>>
>>> I try to use rap and rcp parallel created from the same ui-code. With
>>> factory-interfaces this works until now. But I want to have an
>>> ApplicationContext as singleton. On rap-side I have to use the
>>> abstract SessionSingletonBase. But this can not be encapsulated to an
>>> interface so I dont know how to have the same static getInstance()
>>> acces to a singleton object on rap and rcp.
>>>
>>> Has anyone solved this problem?
>>>
>>> Thanks and regards,
>>> Peter
>>
>>
>
>> Hi,
>>
>> just a sketch how it could be done, don't say that thats the
>> one-and-only way...
>>
>> The Idea is not to use a classical Singleton approach with only one
>> class. I combine it with a kind of factory that is used in the
>> singleton to get the singleton implementation of choice. To do this I
>> use to Interfaces:
>>
>> public interface IMySingleton {
>>
>> }
>>
>> public interface IMySingletonFactory {
>> IMySingleton getInstance();
>> }
>>
>> One for the actual singleton type and one for the factory that creates
>> the instance. The singleton class itself has the expected
>> getInstance() plus a register method with which the appropriate
>> factory could be registered. This must be done before the first call
>> to getInstance() of course:
>>
>> public class MySingleton implements IMySingleton {
>>
>>
>> private static IMySingletonFactory factory;
>>
>> public static void register( final IMySingletonFactory factory ) {
>> MySingleton.factory = factory;
>> }
>>
>> public static IMySingleton getInstance() {
>> return factory.getInstance();
>> }
>> }
>>
>> At last you need the implementations. This can be done somehow like
>> the following. As there is not much to do for the factory one can also
>> combine the implementation of the factory and the interface type in
>> one class as shown with the 'real singleton':
>>
>> class MySessionSingletonFactoryImpl implements IMySingletonFactory{
>>
>> public IMySingleton getInstance() {
>> return MySessionSingletonImpl.getInstance();
>> }
>>
>> }
>> class MySessionSingletonImpl
>> extends SessionSingletonBase
>> implements IMySingleton
>> {
>> public static IMySingleton getInstance() {
>> return ( IMySingleton )getInstance( MySessionSingletonImpl.class );
>> }
>> }
>>
>> class MyRealSingleton
>> implements IMySingleton, IMySingletonFactory
>> {
>> public IMySingleton getInstance() {
>> [...]
>> }
>>
>> Hope that helps!
>>
>> Ciao
>> Frank
>>
>>
>> "Peter Fischer" <pfischer06@fast-mail.org> schrieb im Newsbeitrag
>> news:f84gfj$85o$1@build.eclipse.org...
>>> Hello,
>>>
>>> I try to use rap and rcp parallel created from the same ui-code. With
>>> factory-interfaces this works until now. But I want to have an
>>> ApplicationContext as singleton. On rap-side I have to use the
>>> abstract SessionSingletonBase. But this can not be encapsulated to an
>>> interface so I dont know how to have the same static getInstance()
>>> acces to a singleton object on rap and rcp.
>>>
>>> Has anyone solved this problem?
>>>
>>> Thanks and regards,
>>> Peter
>>
>>
|
|
|
|
|
Re: SessionSingletonBase encapsulated [message #107178 is a reply to message #107165] |
Tue, 30 September 2008 10:20  |
Eclipse User |
|
|
|
Ok. Thank you very much. I will have a look at this.
Roland
Ben W. schrieb:
> on the first view it seems that you want to work with a static registry
> object, but static in this context means the same object for every
> session, as we already concluded. so either you remove the static
> attributes from the register class and work with local objects or you:
>
> - remove everything static from the register class
> - extend the register class from SessionSingletonBase and implement the
> methods
> - replace Register.blabla() calls with Register.getInstance().blabla()
> calls
>
> Thus you'll only work with one object throughout the session, as if you
> would use one static object in a single-user application.
>
> The documentation of SessionSingletonBase should give you some hints.
>
>
> greets
> -ben
>
> Roland Siebert schrieb:
>> Hi,
>>
>> I don't know how I explain what I want, cause my english is not so good.
>>
>> I have put an exapmle project in the attachment, that shows what I want.
>> Hope this will help.
>>
>> Roland
>>
>> Ben W. schrieb:
>>> hi,
>>>
>>> the question is, why do you want a composite to be a
>>> session-singleton? RAP handles the session related stuff when using
>>> GUI stuff.
>>>
>>> do you maybe just want to encapsulate session unique
>>> data/handlers/etc.?!
>>>
>>> greets
>>> -ben
|
|
|
Powered by
FUDForum. Page generated in 0.05000 seconds