[squeak-dev] versioning objects

Colin Putney cputney at wiresong.ca
Wed Apr 16 03:46:33 UTC 2008


On 15-Apr-08, at 3:15 PM, Jimmie Houchin wrote:

> Currently I am implementing accessors which simply create an
> OrderedCollection for each attribute.
>
>
> id: anObject
>    id ifNil: [
>        id := OrderedCollection new.
>        id add: anObject].
>    (id = anObject) ifFalse: [id add: anObject]
>
>
> obj id
>    ^ id last
>
>
> Is there a more standard or better way to offer such features?

I think an important thing to consider is the unit of work that will  
be undoable. If it's "revert #id of <some object> to the previous  
value" then your ordered collection scheme is probably not bad. But if  
there are more complex actions that need to be undo, this kind of  
thing will be difficult.

The usual way to do this is to have all your undoable units of work be  
implemented by "command" objects that know how to perform a specific  
action. Then when the user does something undoable, you create a  
command, execute it, then push it on the undo stack. To undo you can  
either have the command know how to undo its self, or have it create  
an "inverse" command. This kind of thing works pretty well, and it can  
be extended with other features like redo, logging, journal-and- 
snapshot persistence etc.

Hope this helps,

Colin



More information about the Squeak-dev mailing list