Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Copy edit for NullObject readme#109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
domnikl merged 1 commit intoDesignPatternsPHP:masterfromBilge:patch-2
Nov 5, 2014
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletionsBehavioral/NullObject/README.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,15 +2,13 @@

## 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
be a pattern. Furthermore it is a really good pattern in my opinion:
NullObject is not a GoF design pattern but a schema which appears frequently enough to be considered a pattern. It has the following benefits:

*the codein the clientissimple
*it reducesthe chance of null pointerexception
*less "if" => less test cases
*Client code issimplified
*Reducesthe chance of null pointerexceptions
*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
a statement like `if (!is_null($obj)) { $obj->callSomething(); }` anymore.
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.

## Examples

Expand All@@ -21,4 +19,4 @@ a statement like `if (!is_null($obj)) { $obj->callSomething(); }` anymore.

## UML Diagram

![Alt NullObject UML Diagram](uml/uml.png)
![Alt NullObject UML Diagram](uml/uml.png)

[8]ページ先頭

©2009-2025 Movatter.jp