How to use SmartRefStream

German Arduino gsa at softhome.net
Wed Aug 18 09:52:23 UTC 2004


Jon Hylands wrote:
> On Mon, 16 Aug 2004 10:35:29 -0300, "Germán S. Arduino" <gsa at softhome.net>
> wrote:
> 
> 
>>| rr |
>>rr := SmartRefStream fileNamed: 'MyModel.obj'.
>>rr nextPut: MyModel someInstance.
>>rr close.
> 
> 
> In general, this is a bad way to handle sole-instance classes. You should
> have a class variable called 'SoleInstance' or 'Current' or something like
> that, and write accessor methods on the class side to get and set it:
> 
> MyModel class >> #soleInstance
> 
> 	"If you want SoleInstance to self-initialize, un-comment the
> 	following expression:
> 	SoleInstance isNil
> 		ifTrue: [self initializeSoleInstance]."
> 
> 	^SoleInstance
> 
> MyModel class >> #soleInstance: aModel
> 
> 	SoleInstance := aModel
> 
> That way you always know you have a reference to the instance you want.
> 
> Now, when you go to read it in from your file, you can just do this:
> 
> | rr |
> rr := SmartRefStream fileNamed: 'MyModel.obj'.
> MyModel soleInstance: rr next.
> rr close.
> 
> Now you've got the right instance, and you can reference it from anywhere.
> 
> Later,
> Jon
> 
> --------------------------------------------------------------
>    Jon Hylands      Jon at huv.com      http://www.huv.com/jon
> 
>   Project: Micro Seeker (Micro Autonomous Underwater Vehicle)
>            http://www.huv.com
> 
> 

Hmmm, the singleton way, ok will try.

Thanks by the response, also thanks to Scott and Ken.

Regards.
gsa.




More information about the Squeak-dev mailing list