Uzytkownik "Patricia Shanahan" <pats@acm.org> napisal w wiadomosci
news:3xtli.6930$Od7.4456@newsread1.news.pas.earthlink.net...
Thomas wrote:
I have to implement a simple class hierarchy :
List (two directions ;))
/ \
/ \
Queue Stack
The thing is List has more methods than Q and S. Should I make the
methods,
which aren't common private or use the interface mechanism ? Are there
other
ways two do that model inheritence in java ?
You cannot reduce an inherited method from public to private, because
that breaks the superclass contract.
Why extend List at all?
You could write a class Queue that has exactly the methods you think a
queue should have, no more and no less. Have a List reference as an
instance variable and implement the Queue methods by manipulating your
List.
Similarly, a Stack implementation could use a List reference to do most
of the work, without extending List.
Patricia
ok thx Yes, this might be a solution, but the constraints about the
hierarchy I gave are still for that lab (I; m a student :). As i remember
in c++ i had had to write the same. Then i just extended the classes as
above, override the useless methods to empty method {} and C&P the others
needed (since i dont have the code, i dont rembember I did the last one).
Just wondering isn't any more elegant solution to do this.
OK - you have to conform to lab exercise requirements.
that is thrown e.g. by java.util collection classes to indicate that an
this particular implementation. I would throw that from any method that
hierarchy.
public in List will be available in both Stack and Queue.