From: Dave Thomas Date: 2001-08-16T21:42:42+09:00 Subject: [ruby-talk:19890] Re: Why not?: Assigning to self "Pit Capitain" writes: > 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? If you were to allow that, what is the difference between a Square and a Rectangle as classes? Why differentiate? Perhaps the underlying Shape class should have a #has_equal_sides? method? I can see a use for some kind of delegation-on-steroids facility, where you could say: my_object.responds_as other_object Implemented in the interpreter, this would give you useful semantics without (much of) a speed penalty. However, I can't see any use for 'becomes.' My bias here comes from the fact that in Ruby classes are not types, and types are not classes. (In a way it's a shame that there's a built-in #type method, because this is misleading.) If we had a #becomes that swapped an object's class, it would be a subtle but profound shift in the underlying language, giving classes more significance than they deserve. Dave