mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-01 13:42:40 +02:00
Copy edit for NullObject readme
This commit is contained in:
@ -2,15 +2,13 @@
|
|||||||
|
|
||||||
## Purpose
|
## Purpose
|
||||||
|
|
||||||
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
|
NullObject is not a GoF design pattern but a schema which appears frequently enough to be considered a pattern. It has the following benefits:
|
||||||
be a pattern. Furthermore it is a really good pattern in my opinion:
|
|
||||||
|
|
||||||
* the code in the client is simple
|
* Client code is simplified
|
||||||
* it reduces the chance of null pointer exception
|
* Reduces the chance of null pointer exceptions
|
||||||
* less "if" => less test cases
|
* Fewer conditionals require less test cases
|
||||||
|
|
||||||
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
|
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.
|
||||||
a statement like `if (!is_null($obj)) { $obj->callSomething(); }` anymore.
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user