29 lines
835 B
Java
Raw Normal View History

package com.iluwatar.nullobject;
2015-03-04 22:59:42 +02:00
/**
*
* Null Object pattern replaces null values with neutral objects. Many times this simplifies
* algorithms since no extra null checks are needed.
* <p>
* In this example we build a binary tree where the nodes are either normal or Null Objects. No null
* values are used in the tree making the traversal easy.
2015-03-04 22:59:42 +02:00
*
*/
public class App {
/**
* Program entry point
*
* @param args command line args
*/
public static void main(String[] args) {
2015-03-04 22:59:42 +02:00
Node root =
new NodeImpl("1", new NodeImpl("11", new NodeImpl("111", NullNode.getInstance(),
NullNode.getInstance()), NullNode.getInstance()), new NodeImpl("12",
NullNode.getInstance(), new NodeImpl("122", NullNode.getInstance(),
NullNode.getInstance())));
root.walk();
}
2015-03-04 22:59:42 +02:00
}