> No, you can't cast in that direction between those object types. The
> subclass is a different class because presumably it has added new
[quoted text clipped - 7 lines]
> could be casted to your original subclass because that is the runtime
> type.
> I think I am confused because if MyObjectBean (implicitly) extends
> Object and MyObject extends MyObjectBean, isn't MyObject just a
> specilization of MyObjectBean and is then bound to at the very least
> have the members that MyObjectBean contains?
Yes. But you are trying to use it the other way around; an instance of
MyObjectBean does not have the behaviour (or fields) introduced in the
subclass.
> My problem is this: I need some mechanism to add methods (perform
> operations) on otherwise method-less beans,
No, you need a class with methods that operate on the beans. Look at
the Visitor pattern.
http://www.dofactory.com/Patterns/PatternVisitor.aspx
Note: You do not need to modify your beans to have an
"accept(Visitor)" method, just call the Visitor's visit*() method
yourself.
> So I though, why not just enherit from the basic bean and add the
> features I need for business processing further down the
> call-hierachy.
But then the _objects_ need to be of the new type and not the original
type.
Casper B - 11 Mar 2005 11:46 GMT
Thanks Tor,
I've only seen the visitor pattern utilized in recursive tree-walking
but indeed it seems to solve my problem as well!
Regards,
Casper