On Thu, Aug 16, 2001 at 05:40:48PM +0900, Pit Capitain wrote:
> I just remembered another situation where "become" could be 
> useful. I saw it somewhere sometime, but don't remember the 
> details.
> 
> Take the famous Shape class hierarchy:
> 
> class Shape; ...; end
> class Rectangle < Shape; ...; end
> class Square < Rectangle; ...; end

This is a somewhat problematic hierarchy. Suppose that the Rectangle has a
method set_shape(width, height). The square will inherit it, but it will not
make sense for squares.

> Suppose you have a Rectangle instance and use one of its resizing 
> methods so that the new height equals the new width. After that it 
> would be nice if the Object had become a Square instance.

Perhaps, but probably not. It would be very strange when the Rectangle
object suddenly lost its #set_shape method. Everytime you wanted to use
a method on the object, you would have to first figure out whether it 
had changed under your feet and become a different object with different
methods. Or would Rectangle and Square have exactly the same methods?
Then the class would tell you nothing but the current shape of the object
and it would be much better to have an #isSquare method, instead.

I don't doubt that valid use cases where #become simplifies the design, can
be found. But it seems as something that is all too easy to slap on as a
quick-and-dirty-fix to a problem that has better solutions.

// Niklas