The Null Object

Intent

Rather than using a null reference when an object is absent, create an object which implements the expected interface but whose methods have no behavior.

Many of the behavioral design patterns such as State and Strategy allow implementation to vary without specializing clients. Often when a behavior or algorithm has many different versions, one of those versions may be to have no behavior at all. To avoid putting special-case conditional code, “if(!null)” for example, into clients, a Null Object can be used.

Continue reading “The Null Object”