Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to reinforce singleton pattern in extension point
How to reinforce singleton pattern in extension point [message #630788] Tue, 05 October 2010 01:53 Go to next message
Carusyte Missing name is currently offline Carusyte Missing nameFriend
Messages: 27
Registered: July 2009
Junior Member
My question is related to the extension points and extension mechanism in RCP development, I followed the tutorial (
http://www.vogella.de/articles/EclipseExtensionPoint/article .html)
and successfully made my own custom extension, but now that every time the following code is called, a new instance is created:
final Object o = e.createExecutableExtension("class");

Now I wonder how to reinforce the singleton pattern in this mechanism? Do I have to code my own "Manager" like class to maintain the instance, or is there any recommended way of doing this? Thanks in advance.

[Updated on: Tue, 05 October 2010 01:54]

Report message to a moderator

Re: How to reinforce singleton pattern in extension point [message #630805 is a reply to message #630788] Tue, 05 October 2010 06:12 Go to previous message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 05.10.2010 03:54, Jharsseph wrote:
> My question is related to the extension points and extension mechanism
> in RCP development, I followed the tutorial (
> http://www.vogella.de/articles/EclipseExtensionPoint/article .html)
> and successfully made my own custom extension, but now that every time
> the following code is called, a new instance is created: final Object o
> = e.createExecutableExtension("class");
> Now I wonder how to reinforce the singleton pattern in this mechanism?

Extension points don't solve this problem for you, you need to handle
that manually. Note that this can never be a real singleton in the
strict sense, because obviously the to be constructed instances must
have a public default constructor and thus anyone can create an
arbitrary number of objects of this type.

> Do I have to code my own "Manager" like class to maintain the instance,
> or is there any recommended way of doing this? Tanks in advance.

I'm still not sure how you define "singleton" here. But assuming that
you mean that your extension point machinery shall only create one
object per given user-extension, this can be easily managed by you,
because you are already iterating through all contributions. This means
that you could define a proxy object for each contribution that
contains a single handle to the to-be-constructed object. At the point,
where construction is necessary, you do that at the latest possible
point. Typically this means that you keep an IConfigurationElement
element as the factory for this object.

HTH & Greetings from Bremen,

Daniel Krügler
Previous Topic:set a menu visible after job
Next Topic:presentationFactories extension
Goto Forum:
  


Current Time: Thu Apr 25 14:47:56 GMT 2024

Powered by FUDForum. Page generated in 0.03863 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top