Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Singleton Class
Message
 
 
To
03/11/2005 09:36:06
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Title:
Miscellaneous
Thread ID:
01064942
Message ID:
01065006
Views:
19
David,

>1) Can I avoid that a user can call CREATEOBJECT directly, bypassing the GetSingleton method ?

You can look to make sure GetSingleton() is on the calling stack (use astackinfo() or program(...)) and refuse to instantiate the object if it's not.

>2) Can I avoid that a user redefines the Init method in the subclass ?

You probably don't really want to do this. Suppose my subclass wants to extend your Singleton and I really do have to do something else at Init() time? As long as I call dodefault() everything should still work. You can use getpem() to see if the method has been overridden.

>3) Can it be done so that it is possible to assign the result of GetSingleton to a local variable ? For the moment, if someone does so, the created instance is then not listed in the AINSTANCE array, and a next call will create a second Singleton.

Yes it is possible to store it to a local memvar. You might want to do a search of the threads here there are other API and DDE based methods to query for the existence of a singleton that solve the ainstance() problem.
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform