Hi Miguel,<br>  A simple rule you can use is:<br><br>  Use a class variable if your Singleton will not have subclasses.<br>  Use a instance class instance variable if your Singleton will have one or many subclasses, i.e. each class in the hierarchy will need its own Singleton copy.<br>
<br>  A good practice is to implement a #reset method, very useful when cleaning or shutting down images for a release.<br><br>Best regards<br><br>Hernán<br><br><br><div class="gmail_quote">2009/8/4 Miguel Enrique Cobá Martinez <span dir="ltr">&lt;<a href="mailto:miguel.coba@gmail.com">miguel.coba@gmail.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">What is the difference between a class variable like Current in Locale<br>
class:<br>
<br>
Object subclass: #Locale<br>
        instanceVariableNames: &#39;id shortDate longDate time decimalSymbol<br>
digitGrouping currencySymbol currencyNotation measurement<br>
offsetLocalToUTC offsetVMToUTC dstActive&#39;<br>
        classVariableNames: &#39;Current CurrentPlatform KnownLocales<br>
LanguageSymbols LocaleChangeListeners PlatformEncodings&#39;<br>
        poolDictionaries: &#39;&#39;<br>
        category: &#39;System-Localization&#39;<br>
<br>
that is accessed as (in class side):<br>
<br>
current<br>
        &quot;Current := nil&quot;<br>
        Current ifNil: [<br>
                Current := self determineCurrentLocale.<br>
                &quot;Transcript show: &#39;Current locale: &#39; , Current localeID asString;<br>
cr&quot;].<br>
        ^Current<br>
<br>
and current in SmalltalkImage class side:<br>
<br>
SmalltalkImage class<br>
        instanceVariableNames: &#39;current&#39;<br>
<br>
that is accessed as:<br>
current<br>
        &quot;Note that this could be implemented differently to avoid the test&quot;<br>
<br>
        current isNil<br>
                ifTrue: [current := self basicNew].<br>
        ^ current<br>
<br>
I&#39;m trying to create a singleton but I have some doubts in the correct<br>
implementation.<br>
<br>
I have also seen the explanation on<br>
<br>
<a href="http://coweb.cc.gatech.edu/cs2340/3872" target="_blank">http://coweb.cc.gatech.edu/cs2340/3872</a><br>
<br>
also:<br>
<br>
<a href="http://stackoverflow.com/questions/438729/smalltalk-singleton-pattern-how-do-i-initialize-the-instance-variables" target="_blank">http://stackoverflow.com/questions/438729/smalltalk-singleton-pattern-how-do-i-initialize-the-instance-variables</a><br>

<br>
that corresponds to the first type, using (I suppose) a class variable<br>
and<br>
<br>
<a href="http://wiki.squeak.org/squeak/939" target="_blank">http://wiki.squeak.org/squeak/939</a><br>
<br>
that corresponds to the second type.<br>
<br>
Are there guidelines or pros/cons about singletons on Smalltalk?<br>
<br>
Thanks,<br>
Miguel Cobá<br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@lists.squeakfoundation.org">Beginners@lists.squeakfoundation.org</a><br>
<a href="http://lists.squeakfoundation.org/mailman/listinfo/beginners" target="_blank">http://lists.squeakfoundation.org/mailman/listinfo/beginners</a><br>
</blockquote></div><br>