forked from iluwatar/java-design-patterns
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.java
More file actions
28 lines (25 loc) · 835 Bytes
/
App.java
File metadata and controls
28 lines (25 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.iluwatar.nullobject;
/**
*
* 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.
*
*/
public class App {
/**
* Program entry point
*
* @param args command line args
*/
public static void main(String[] args) {
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();
}
}