On Feb 21, 2006, at 10:34 PM, Joseph J. Strout wrote:
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.
My full original statement here included "there are uses for both
versions; and this doesn't detract from the other excellent
advantages of having first-class classes". The "You can't store a
reference..." line you're responding to followed that, so was about
first-class classes, not singletons (which you can do very cleanly as
a special case of first-class classes).
So just to be clear: I think first-class classes are great, with this
and many other uses. REALbasic doesn't remotely support first-class
classes right now. I think it should. The original post that started
all this would seem to have been looking for a clean, quick way of
doing first-class classes, which, indeed, first-class classes (*if*
they included a class constructor) would provide.
Guyren G Howe
[EMAIL PROTECTED]
http://relevantlogic.com
1 512 538 0655
REALbasic, PHP, Python programming
PostgreSQL, MySQL database design and consulting
Technical writing and training
_______________________________________________
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>