in reply to Re^2: displaying package variable from inherited method.
in thread displaying package variable from inherited method.
By the way there must be a name for what I'm trying to do, is it "object introspection"?
More like "breaking encapsulation".
The whole point of classes and objects is polymorphism. That is, given an object, you don't care what its specific type is as long as it supports the operations you want to perform on it in a meaningful way.
In your specific case, there's a perfectly good way to get that instance data without relying on package variables or symbolic references or even caring about the specific type of the class. That way is calling a method.
With only a couple of classes, it might look like you're duplicating data by overriding methods. Maybe so... but it takes little imagination to see an expanded system with more subclasses, some of which can reuse their parent data (and good luck coding around that by accessing package variables symbolically!) and others that can override the parent method to call it and add, delete, or modify just one particular field in the results.
You're making a lot more work for yourself trying to work against the object system. Embrace it!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: displaying package variable from inherited method.
by wazoox (Prior) on Jun 10, 2006 at 20:26 UTC | |
by chromatic (Archbishop) on Jun 10, 2006 at 22:55 UTC | |
by wazoox (Prior) on Jun 11, 2006 at 12:57 UTC |