Tag Info

New answers tagged

3

You don't expose what the user doesn't need to know. If the main interface is just DList, then you should not expose DListNode to the user of your class(es). You may make DListNode a private class, which is manipulated internally by DList only. In the case of iterating through your list, e.g. next(), you may move this to an enumerator or iterator like ...


1

You can add an attribute myDList to the class DListNode and implement a method like next in the following manner: public DListNode next(DListNode node) { if (node == null) return null; if(node.getMyDList()!=this) throw // ...some exception here if (node.getNext() == this.sentinel) return null; return node.getNext(); } That ...


1

Your major problem comes from the user passing a node that do not belong to the list, as you said in your comment: [...] if the user passes node of list1 to list2 by saying list2.someMethod(nodeOfList1) You could try to avoid letting the user manipulate nodes, in which case you would need an indirect way to access them, but this pushes the problem ...



Top 50 recent answers are included