Null object pattern
In object-oriented computer programming, a null object is a behavioral pattern designed to act as a default value of an object.
Motivation
In some object-oriented languages, such as Java, variables may be null. As these variables do not have methods, they cannot be used and variables may need to be checked to ensure they are not null. This tends to make code less readable, so a special class of variables, with an identical interface are created to which variables of the class can be initialised.
It is not a pattern from Design Patterns, but is mentioned in Martin Fowlers Refactoring[1] in the Insert Null Object refactoring.
References
- ^ *Fowler, Martin (1999). Refactoring. Improving the Design of Existing Code. Addison-Wesley. ISBN 0-201-48567-2.
External Links
Jeffrey Walkers' account of the Null Object Pattern Antonio Garcias' account of the Null Object Pattern Martin Fowlers' description of Special Case, a slightly more general pattern