Null Object Pattern
noun
say it: “NUL OB-jekt PAT-urn” /nʌl ˈɑbdʒɛkt ˈpætərn/
A design pattern that replaces a missing object with a stand-in that keeps the same promise and does nothing.
What is the Null Object pattern?
The Null Object pattern replaces "nothing here" (null) with an object that keeps the same promise and safely does nothing. A room with no speaker gets a NoSpeaker whose play and stop do nothing, so every routine can call room.speaker.play(...) without first asking whether there is one. Skip it when something missing must be noticed, such as a lock.
In a sentence
- “The bedroom's null object speaker meant no routine ever had to ask whether a room had one.”
Level: Journeyman · More OOP terms at this level
Updated