realbasic-nug
[Top] [All Lists]

Re: Constructors for Modules

To: REALbasic Network Users Group <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Constructors for Modules
From: Will Leshner <leshner at ljug dot com>
Date: Wed, 30 Jul 2003 11:20:56 -0700
While not ideal, I've been experimenting with an approach. I create one module into which I put all of my singletons. In that one module I create one property and method. Say I want a singleton "Thing". I create a class CThing, then I create a property in my Singleton module called mThing and a Thing method. The Thing method looks something like:

function Thing() as CThing
        if not mThing then mThing = new CThing
        return mThing
end function

Then, in my code, I can do stuff like:

Thing.SomeMethod

And the right thing happens.

Joseph J. Strout wrote:

Because a class is useless by itself; you have to have an object. Sometimes a Singleton object is the right approach, but often not -- and even when it is, in RB, you would need a module to manage your singleton instance. That's a nuisance.




---
A searchable archive of this list is available at:
<http://support.realsoftware.com/listarchives/search.php>

Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>
.


<Prev in Thread] Current Thread [Next in Thread>