开发者

Java: implementing MutableTreeNode, remove similar old methods?

I'm getting closer to fully implementing a JTree to represent a collection of Series. The hierarchy is Show > Season > Episod开发者_StackOverflow社区e.

These are all classes and each one of them implements the MutableTreeNode interface. When starting this project I didn't know that I was going to need this interface, so I defined methods like 'removeFromSeason' in Episode, 'add(Episode ep)' in Season,..

Now that I'm implementing this MutableTreeNode interface I see that many methods overlap. So I'm wondering how I should handle this. For example: the add(Episode ep) in just takes an Episode as argument, while the 'insert(MutableTreeNode child, int index)' uses 2 arguments, the child and the index. In the add episode I just added the episode to the ArrayList at a random position. Each Episodes has a variable containing the number of the Episode so that wasn't a problem.

If I fully replace the add Method, I should also be giving the index of the Episode, which could complicate the ArrayList. Or I would be doing double work, passing the episode and the episode.getNumber() as arguments, which seems stupid to me.

I could also keep both the original methods and the new ones, and let the one call the other. This would doesn't really seem right to me.

What are your opinions on how to handle this? Any comment is appreciated :)

Harm


When I want to implement a tree, I provide an implementation of TreeModel and I do all the tree handling in it. I never implement TreeNode or MutableTreeNode (A node doesn't need to implement any interface). This frees the business objects from UI concerns. Of course, the TreeModel must be somehow notified when changes happen.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜