mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-14 20:58:35 +00:00
Reformat rest of the design patterns - Issue #224
This commit is contained in:
@@ -2,35 +2,27 @@ 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.
|
||||
* 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.
|
||||
* 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())));
|
||||
public class App {
|
||||
/**
|
||||
* Program entry point
|
||||
*
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
root.walk();
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user