How to store/load alternate object representations?

Ned Konz ned at bike-nomad.com
Tue Aug 6 04:36:30 UTC 2002


On Monday 05 August 2002 09:09 pm, Ned Konz wrote:

> Problem is, when I store a project it still stores MorphProperties
> obejcts (which don't load into older images).

Never mind; it wasn't really storing MorphProperties -- I had a change 
set browser in the project that had in it a reorganization for the 
MorphProperties class itself, and then it wasn't able to find the 
class from the DiskProxy.

It works fine when I change to an empty change set and close the 
change set browser.

But here's a question: there are two mechanisms available for 
tinkering with objects at store and load times:

objectForDataStream: (high level)
storeDataOn: (low level)

comeFullyUpOnReload: (high level)
readDataFrom:size: (low level)

as well as convertToCurrentVersion:refStream:, which I'm using too to 
deal with old projects being filed into new images.

How do I decide on which of these (high/low level) to use for a given 
class? Right now I have all four of these overridden, but is this 
overkill?

--------- MorphExtension --------

objectForDataStream: aStream
	otherProperties ifNotNil: [ aStream replace: otherProperties with: 
(IdentityDictionary newFrom: otherProperties) ].
	^self

comeFullyUpOnReload: smartRefStream
	"inst vars have default boolean values."
	locked ifNil: [locked _ false].
	visible ifNil: [visible _ true].
	sticky ifNil: [sticky _ false].
	isPartsDonor ifNil: [isPartsDonor _ false].
	otherProperties _ MorphProperties convertedFrom: otherProperties.
	^ self

storeDataOn: aDataStream
	"Store my properties as an IdentityDictionary for backwards 
compatibility"
	| oldProps |
	oldProps _ otherProperties.
	otherProperties _ otherProperties ifNotNil: [ IdentityDictionary 
newFrom: otherProperties ].
	[ super storeDataOn: aDataStream ] ensure: [ otherProperties _ 
oldProps ]

readDataFrom: aDataStream size: varsOnDisk
	"Fill in the fields of self based on the contents of aDataStream.  
Return self.
	 Read in the instance-variables written by Object>>storeDataOn:."
	super readDataFrom: aDataStream size: varsOnDisk.
	otherProperties _ MorphProperties convertedFrom: otherProperties.
---------

I see that most classes that want to store a DiskProxy seem to do so 
in objectForDataStream:.

But beyond that, are these interchangeable? How do you choose which to 
use?

Thanks,
-- 
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE




More information about the Squeak-dev mailing list