Paul Clapham wrote:In my opinion the idea of having a separate class for LeafNode is questionable. .
As for BinaryNode, it's even worse because it violates the Zero-One-Infinity rule.
Thanks for the reply. I know what you mean and I strongly agree with you.
However, the requirement comes from a programming exercise, which claims that the whole point is to give exercise takers some ideas on how to separate interface from implementation and use of abstract class for elimination of duplicate code.
The solution has one interface for AbstractTreeNode and every node type inherits the AbstractTreeNode. So when using the three types of nodes, people can just do:
and stuff like that. It will also enable other developers to use
polymorphism when accepting my_node into functions written by them.
I've got no problem understanding the idea, but it just sounds bad to me that a class has some meaningless methods defined in its interface. However, I do hear that such things happen in Swing's implementation. If I recall correctly, it's JComponent or something (Is it true? I'll be very happy if someone can verify this). So I start to get confused ... mainly about that a class has meaningless methods in its interface. Is it a bad design that should always be avoided? or something that is still acceptable in industry/academia whatever?
Thanks.