What is the difference between a class variable like Current in Locale class:
Object subclass: #Locale instanceVariableNames: 'id shortDate longDate time decimalSymbol digitGrouping currencySymbol currencyNotation measurement offsetLocalToUTC offsetVMToUTC dstActive' classVariableNames: 'Current CurrentPlatform KnownLocales LanguageSymbols LocaleChangeListeners PlatformEncodings' poolDictionaries: '' category: 'System-Localization'
that is accessed as (in class side):
current "Current := nil" Current ifNil: [ Current := self determineCurrentLocale. "Transcript show: 'Current locale: ' , Current localeID asString; cr"]. ^Current
and current in SmalltalkImage class side:
SmalltalkImage class instanceVariableNames: 'current'
that is accessed as: current "Note that this could be implemented differently to avoid the test"
current isNil ifTrue: [current := self basicNew]. ^ current
I'm trying to create a singleton but I have some doubts in the correct implementation.
I have also seen the explanation on
http://coweb.cc.gatech.edu/cs2340/3872
also:
http://stackoverflow.com/questions/438729/smalltalk-singleton-pattern-how-do...
that corresponds to the first type, using (I suppose) a class variable and
http://wiki.squeak.org/squeak/939
that corresponds to the second type.
Are there guidelines or pros/cons about singletons on Smalltalk?
Thanks, Miguel Cobá