Introduce Null Object

From CSSEMediaWiki
Revision as of 02:48, 28 September 2008 by Geoffrey Clark (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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

Example.jpg

Personal tools