[Seaside] How generate ID
Tom Phoenix
rootbeer at redcat.com
Sat Dec 29 20:53:45 UTC 2007
On Dec 29, 2007 12:11 PM, an organic <seasidebeginner at gmail.com> wrote:
> i am writing small example in squeak seaside. I want save my objects in
> image. And i have this class Category with ID, Name. Store in
> OrderedCollection. My problem how generate next ID? i think about locking
> and find max increase one and use it but isn't there simplier way?
I'm not completely sure what you're looking for. It sounds as if you
want a class-side variable, something like this:
Object subclass: #MyClass
instanceVariableNames: ''
classVariableNames: 'LastID'
poolDictionaries: ''
category: 'MyCategory'
MyClass class>>initialize
super initialize.
LastID := ifNil: [ LastID := 0 ] .
MyClass>>newID
^(LastID := 1 + LastID).
Because it's a class variable, it will exist just once in the system,
instead of once for each instance of MyClass. That means that #newID
will always return a different value than the previous time, no matter
which instance receives it. Is that what you're looking for?
--Tom Phoenix
More information about the seaside
mailing list