Hi,
You are doing the same mistake as in your famous
thread Why can only "real" dog bark?"!
You are declaring "adoer" as a Doer, in the code line
Doer adoer = new ADoer();.
And Doer does not how to xy().
You can write ADoer adoer = new ADoer(). There is no problem about that. Choosing between
ADoer adoer= new ADoer() and
Doer adoer = new ADoer() depends on your goals.
For exemple, let's say you are working with states.
You may have an interface State, which has a method nextState(). Then you have subclasses like IdleState and RunningState.
You may have a declaration like:
State myState; or
State []myStateCollection;
then myState can either be a IdleState or a RunningState in the course of your program.
If you'd declared:
IdleState myState; you are done with it. myState is an IdleState, and will remain an IdleState all its life.
myStateCollection can contain either IdleState or RunningState, it does not have to care about what specific state it is, it is a State, that's all.
And a client using myStateCollection will only be aware of that: myStateCollection contains State's. Thus, it is only allowed to send to those instances, messages which are declared in the State interface.
If RunningState has a specialisation (like a stop method), you can not write
myStateCollection[0].stop() even if you know you have add only RunningState in it, because you do not meet the contract of the State interface.
W.
[ August 07, 2002: Message edited by: Wilfried LAURENT ]