[squeak-dev] Re: Question about class and instance

Igor Stasenko siguctua at gmail.com
Fri Oct 12 23:25:39 UTC 2012


On 12 October 2012 21:50, Yanni Chiu <yanni at rogers.com> wrote:
> 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 when you want to limit the amount of messages your sole object
can understand.
With classes it is not that easy :)

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

yes, i remember, at the beginning, when i just started using
smalltalk, i also had concerns about "all those objects staying in
memory,
and who knows what happens with them.. maybe something nasty ;)"


-- 
Best regards,
Igor Stasenko.


More information about the Squeak-dev mailing list