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: William Squires <wsquires at satx dot rr dot com>
Date: Wed, 30 Jul 2003 17:13:55 -0500
Cc: William Squires <wsquires at satx dot rr dot com>
No, you could need a class - like in Java (particularly the .Math namespace) - so you can have globally available functions in their own namespace that won't collide with other functions in a different namespace (given that the programmer specifies the namespace with something like x = Math.Sin(pi)!) but you don't need to instantiate an object of the Math class. Of course one could argue this is just a module with a namespace, but you could have a class that has class and instance methods as well. To some extent, this is what RB's new Extends keyword does (I think... Or maybe I just don't get the Extends keyword :) )

On Wednesday, July 30, 2003, at 12:56  PM, Joseph J. Strout wrote:

At 1:33 PM -0400 7/30/03, Thomas Reed wrote:

Given that modules are not objects but are still logical holders of global
methods and properties, is it technically possible to add
constructor/destructor functionality to initialize properties?

Sure, it's possible. But why? Wouldn't it make more sense to use a class for this sort of thing?

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.

I have a lot of modules with an Init method, which I have to be sure to call at the beginning of my app. I can certainly see the value in having that method called automatically by the compiler at app startup. (And perhaps another one called when the app is exiting, too.)

Best,
- Joe

--
,------------------------------------------------------------------.
|    Joseph J. Strout           REAL Software, Inc.                |
|    joe at realsoftware dot com       http://www.realsoftware.com        |
`------------------------------------------------------------------'

---
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/>



---
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>