Where do I store permanent Objects? (was [GOODIE] Transcript Logger)

Ned Konz ned at bike-nomad.com
Sat Jun 22 20:24:14 UTC 2002


On Saturday 22 June 2002 10:55 am, Markus Fritsche wrote:
> Ned Konz wrote:
> >Look at the attached change set.
>
> Thank you.
>
> The next question that rises for me is: If I need to store
> permanent objects, how do I do this "the right way"? As a
> class-variable or with "Smalltalk at: #transcriptLogger put:
> (Transcriptlogger new...)"?

Well, your logger would have to open the logfile at startup time. You 
could either do this on a per-instance basis (in which case you could 
either use a global, or a class variable to hold it), or on a 
per-class basis (especially if there's only a single logfile).

Either way, the instance or class should do this (perhaps in an 
initialize method):

	Smalltalk addToStartUpList: self.
	Smalltalk addToShutDownList: self.

and then define a startUp or startUp: method:

startUp: resuming
	resuming ifFalse: [ "open file, etc." ]

and a shutDown or shutDown: method:

shutDown: quitting
	quitting ifTrue: [ "close file, etc." ]

Strictly speaking, the file will be closed at shutdown anyway, but 
it's good form to do this.

Another possibility is to have a per-World log, which you could attach 
to the World (perhaps via a property). You can get notifications from 
the World (though I haven't tried this myself):

	World setProperty: #transcriptLogger toValue: self.
	World when: #aboutToLeaveWorld send: #closeFile to: self.
	World when: #aboutToEnterWorld send: #openFile to: self.

This works because the Projects are global, and they hang on to their 
Worlds.
-- 
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE




More information about the Squeak-dev mailing list