Jump to content

Null object pattern

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Autarch (talk | contribs) at 19:51, 17 January 2007 (Created page with 'In object-oriented computer programming, a '''null object''' is a behavioral pattern designed to act as a [[Default (computer science...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

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

  1. ^ *Fowler, Martin (1999). Refactoring. Improving the Design of Existing Code. Addison-Wesley. ISBN 0-201-48567-2.

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