You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Behavioral/NullObject/README.md
+6-8Lines changed: 6 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -2,15 +2,13 @@
2
2
3
3
##Purpose
4
4
5
-
NullOutput is a example of NullObject pattern. It is not formally a Design Pattern by the GoF but it's a schema which appears frequently enough to
6
-
be a pattern. Furthermore it is a really good pattern in my opinion:
5
+
NullObject is not a GoF design pattern but a schema which appears frequently enough to be considered a pattern. It has the following benefits:
7
6
8
-
*the codein the clientissimple
9
-
*it reducesthe chance of null pointerexception
10
-
*less "if" => less test cases
7
+
*Client code issimplified
8
+
*Reducesthe chance of null pointerexceptions
9
+
*Fewer conditionals require less test cases
11
10
12
-
Every time you have a method which returns an object or null, you should return an object or a`NullObject`. With NullObject, you don't need
13
-
a statement like`if (!is_null($obj)) { $obj->callSomething(); }` anymore.
11
+
Methods that return an object or null should instead return an object or`NullObject`.`NullObject`s simplify boilerplate code such as`if (!is_null($obj)) { $obj->callSomething(); }` to just`$obj->callSomething();` by eliminating the conditional check in client code.
14
12
15
13
##Examples
16
14
@@ -21,4 +19,4 @@ a statement like `if (!is_null($obj)) { $obj->callSomething(); }` anymore.