Jon Hylands wrote:
On Mon, 16 Aug 2004 10:35:29 -0300, "Germán S. Arduino" gsa@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@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.