我正在尝试使用空对象设计模式在列表的开头和结尾实现与空对象的双重链接。所以一个空列表将包含两个空对象。所以我写了这段代码这是否遵循空对象设计模式?如果不是我怎么能做到这一点。任何建议将不胜感激。
更新代码-
// Creating a doubly linked list.
doubleLinkedList = new DoubleLinkedList();
class DoubleLinkedList {
private NewLink firstNode;
private NewLink lastNode;
private NewLink rootNode;
public DoubleLinkedList() {
//So this satisfies my question that I have asked meaning null objects at beginning and last node or something else I have to do.
firstNode = NewLink.NULL_NODE;
lastNode = NewLink.NULL_NODE;
}
}
class NewLink {
public String data;
public NewLink nextPointer;
public NewLink previousPointer;
public static final NewLink NULL_NODE = new NewLink();
public NewLink(String id) {
data = id;
}
public NewLink() {
}
// Overriding toString method to return the actual data of the node
public String toString() {
return "{" + data + "} ";
}
}