On Sun, March 6, 2005 6:26 pm, Jim Weirich said: > On Sunday 06 March 2005 01:17 pm, ES wrote: > >> Generally speaking, using an object this way might not be the best >> idea. If each Point were an immutable, unique instance (think Fixnum, >> for example), I would think it's OK but I'm somewhat leery of this. > > Good points. I see the example uses .freeze on the x and y attributes. This > freezes the objects referenced by @x and @y (and since the objects are > Fixnum, this is a bit pointless. Fixnums are immutable anyways). What it > doesn't do is freeze the binding between @x/@y and those objects. I'm > guessing you really intended the following: > > def initialize(x,y) > @x = x > @y = y > freeze # Freeze the PointID object > end Yep, that would certainly work for a simple solution. For a more complex realization of the idea, I'd consider some sort of a factory object, call it PointSpace, for example. Whenever a user needs a reference to a point that exists within the PointSpace, the factory finds out if there's already a Point for the specified coordinates. If there is, a reference to that is returned, otherwise a new Point is created. Points could of course be removed from the list when there are no references remaining. Pretty standard factory stuff but it'd guarantee a Point's uniqueness -and for syntactical simplicity, Point could certainly internalize/implement PointSpace. > -- Jim Weirich E