[squeak-dev] Re: Question about class and instance
Yanni Chiu
yanni at rogers.com
Fri Oct 12 19:50:46 UTC 2012
On 12/10/12 2:23 PM, Joseph J Alotta wrote:
> Is there a general rule for class and instance?
>
> For example, if there should be only one instance of an object, should it be a class object?
That is the Singleton pattern. Look for examples in the image - try
looking for senders/implementers of #default or #instance.
There's arguments on both sides, whether to use the class object itself
as the singleton, vs. using a single default instance. I think it comes
down to how likely it is that what you thought was a singleton, turns
out not to be, and then you have to move all the methods over from the
class-side to the instance-side.
> Or if I expect it to stay in memory and be available all the time, should it be a class object?
Your words "stay in memory" is a big concern. It indicates that you are
bringing some assumptions about programming from another programming
language/environment, to your learning of Smalltalk/Squeak. IMHO, that's
going to impair your ability to learn how to effectively learn and use
Smalltalk. Try to find articles/tutorials that explain the Smalltalk
image concept, and the concept of live-ness.
More information about the Squeak-dev
mailing list
|