At 8:28 PM -0600 2/21/06, Guyren Howe wrote:

Now that REALbasic 2006 has shared methods and shared properties, is it possible to have a true Singleton object?

Sure -- but then, it was quite possible before too, except that the enforcement was at runtime rather than at compile time.

The current shared methods and properties make the class behave like a module, not like an object (which is what a singleton should be).

The singleton would be an object, of course. The shared method and (perhaps) property are simply convenient places to put the factory (i.e., the method that returns the singleton instance, creating it if necessary). Of course you could put this in a module just as well, but then you can't make the constructor private, which means you have to have run-time enforcement of the contract that only the factory method can create an instance of the singleton class.

You can't store a reference to a class in a data structure, or exploit polymorphism with its shared methods.

So?  None of that is needed to implement the singleton pattern.

Best,
- Joe

--

Joseph J. Strout
[EMAIL PROTECTED]
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to