Introduce Null Object

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
m (New page: ''Summarised from Refactoring'' Martin Fowler 1999 == Motivation == You have repeated checks for a null value For example your code my look like: if (customer == null) plan = Bill...)
 
m
Line 15: Line 15:
 
Replace your check for a null value with a null object
 
Replace your check for a null value with a null object
  
[[Image:Example.jpg]]
+
[[Image:Null Object.jpg]]

Revision as of 02:49, 28 September 2008

Summarised from Refactoring Martin Fowler 1999

Motivation

You have repeated checks for a null value

For example your code my look like:

if (customer == null) plan = BillingPlan.basic();
else plan = customer.getPlan();


Solution

Replace your check for a null value with a null object

Null Object.jpg

Personal tools