tags:

views:

50

answers:

2

I was writing two implementations of a Linked List for an assignment, a Doubly Linked List and a Circular Doubly Linked List. Now as the class representing a Link within the Linked List is the same in both implementations, I want to use it in both.

Now I wonder which approach would be better:

Implement the Link class as a package-private static member class in the first implementation and then use this class in the second implementation or make the Link class a package-private class.

+2  A: 

There is no reason why the Link class should be more closely related to the first implementation than to the second, so I would recommend the second approach.

sepp2k
+4  A: 

You could move Link up as static member class of a common base class / interface (if you have one). This solution would express that Link is strongly associated with (both implementations of) the linked list.

Péter Török
+1 Haven't thought about that but I really like the idea.
Helper Method