Singletons and Extension Points [message #44890] |
Thu, 22 July 2004 12:30  |
Eclipse User |
|
|
|
Hello,
Is it possible to cleanly define a singleton instance of a
class that is specified in an extension point?
My question is based upon the following observations:
1. when using
IConfigurationElement.createExecutableExtension the default
(no-args) constructor is called.
2. if a class is referenced in two extension points, then
it's default constructor will be called twice, breaking the
concept of the singleton.
:-/
The best solution I can think of is to use the extension
point to get access to a non-singleton factory, which then
provides an accessor to a singleton which implements the
interface we're really interested in.
This seems a bit of an indirect, so I'm wondering if there's
a better or a standard solution.
cheers
_______________________________________________
rich rdfx.org
|
|
|
Re: Singletons and Extension Points [message #44989 is a reply to message #44890] |
Thu, 22 July 2004 16:25  |
Eclipse User |
|
|
|
Originally posted by: chaves.nospam.inf.ufsc.br.ok
An instance of the class specified in an extension point will be created
every time someone calls IConfigurationElement#createExecutableExtension.
Using a dummy proxy class that delegates to the singleton object is the
way to go.
Rafael
rich boakes wrote:
> Hello,
> Is it possible to cleanly define a singleton instance of a
> class that is specified in an extension point?
> My question is based upon the following observations:
> 1. when using
> IConfigurationElement.createExecutableExtension the default
> (no-args) constructor is called.
> 2. if a class is referenced in two extension points, then
> it's default constructor will be called twice, breaking the
> concept of the singleton.
> :-/
> The best solution I can think of is to use the extension
> point to get access to a non-singleton factory, which then
> provides an accessor to a singleton which implements the
> interface we're really interested in.
> This seems a bit of an indirect, so I'm wondering if there's
> a better or a standard solution.
> cheers
> _______________________________________________
> rich rdfx.org
|
|
|
Powered by
FUDForum. Page generated in 0.05036 seconds