Pit Capitain wrote:
> Why not? In this class hierarchy each square is a (specialized) 
> rectangle, so class Square also has a method #set_shape. If 
> called with width != height, the Square instance would "become" a 
> Rectangle instance. In a drawing program showing a square, why 
> shouldn't it make sense to be able to drag one side or one hotspot 
> in order to change the square into a rectangle?

That would mean that #set_shape in Square would have to handle all the 
possible parameters for Rectangle, Circle, Ellipse, Triangle, Star, and 
so on. I don't like this degree of interdependence.

You can implement this in Ruby with something like:

   class Square
     def set_shape(x, y) # note the "y" only exists because of Rectangle
       if x != y
         Rectangle.new(x,y) # Square knows about Rectangle, bad coding!
       else
         @x, @y = x, y
         self
       end
     end
   end

   item = shape.set_shape(10, 10)
   item = shape.set_shape(23, 45)

It would be better to abstract this up a level, so a "Shapes" class 
would know about all the possible shapes underneath it, and thus has a 
legitimate reason for knowing the different parameters.

The bonus side of this is that you will no longer have any need for 
"become".

-- 
   spwhite / chariot.net.au