Re: What about real polymorphism ?? [message #42021 is a reply to message #41991] |
Tue, 14 December 2004 09:06   |
JD Smith
Messages: 850 Registered: December 1999
|
Senior Member |
|
|
On Tue, 14 Dec 2004 02:29:57 -0600, Michael Wallace wrote:
>> A singleton is very possible with IDL:
>> Just use a global variable (also as your access point) and
>> check its existance in the constructor.
>
> You know you drive all of us OO guys crazy with comments like "just use
> a global variable"?
>
> There is a big difference between a global variable and a singleton.
> You're only thinking of the access point, not the rest of the pattern.
> I'd be VERY surprised if it's possible to implement a true singleton
> pattern in IDL. I'd love to be proved wrong, but I don't think it's
> possible with IDL's so-called "objects."
>
> Mike
Good Wiki article with description and plusses and minuses on
singletons: http://c2.com/cgi/wiki?SingletonPattern
My favorite quote:
Singleton is a social disease. Because Singleton is so easy to
understand, it is the single pattern that almost anybody who merely
thumbed through GoF at the bookstore can remember and explain. That
leads to unwarranted exuberance for the pattern among those who can
least afford such exuberence.
You *can* implement a singleton in IDL (yes, using a common block or
system variable). Try a search:
http://groups.google.com/groups?as_q=singleton&as_ugroup =*idl-pvwave*
The chief drawback is, since there are no class methods in IDL, either
you can't override or extend the code which enforces "only one
instance" (without modifying it directly), or you have to use a
regular method as if it were a class method, discarding a "dummy"
instance. A bit ugly, but it gets the job done. Note that IDL>6
won't let you delete the self variable in Init, so my old Singleton
class would need changing. I prefer the singleton generator function
technique.
JD
|
|
|