From: Hugh Sasse Staff Elec Eng Date: 2003-08-22T06:45:45+09:00 Subject: Re: Class variables - a surprising result On Fri, 22 Aug 2003, Kurt M. Dresner wrote: > > I have run into this because I'm working on a loans > > system, and each item needs a unique id, which I've allocated as an > > error correcting code. This gives me 46000 items. But if I have to > > use the same class variable to number my users uniquely as well as > > the items they borrow, that uses up space in my limited range. > > Um, this screams "instance variables" to me... Each has an instance var holding its number. Somewhere I must keep the next available number, in such a way that the new item gets a different one. Now I've put it in those terms I might be better having a factory class which has an instance var for the number, and calls the constructor for the object I want numbered with that fresh number.... ... Item.new(@next_free) ... Why didn't I think of that before? Keep the number somewhere else than the class I want to count. > > What does your class represent, a user or a loan? I have users, loans, and items to be loaned. The loans aren't numberd, just the users and items. > > -Kurt > > Hugh