in reply to "polymorphism" hack: nuts or wise?

It seems to me you've just changed the nature of the problem slightly: before, if you created a new specialnode that inherits from node, you had to modify all of the container objects to know about the new type. Now, if you create a new container type specialmatrix object that inherits from matrix, you have to modify all of the containable object to know about this new type.

One way to solve the problem is to use the isa method from UNIVERSAL. You can say if ($obj->isa('Node')) to see if an object is a Node, or inherits from Node.

Replies are listed 'Best First'.
Re^2: "polymorphism" hack: nuts or wise?
by rvosa (Curate) on Aug 30, 2005 at 12:27 UTC
    You can say if ($obj->isa('Node')) to see if an object is a Node, or inherits from Node.
    Is that even necessary? If an object inherits from Node, it'll have the Object->container method in the same way as the parent Node object has (provided, that is, if the object doesn't override the method). Also, it would send me back to a chain of if / elsif / else statements?