Technology Quote by Eric Freeman
““The NoCommand object is an example of a null object. A null object is useful when you don’t have a meaningful object to return, and yet you want to remove the responsibility for handling null from the client.””
About This Quote
Source Book: Head First Design Patterns by Eric Freeman, 2004
A null object provides a harmless default so client code need not check for null before using an object.
In simple terms: Use a default object to avoid null checks.
Implement null objects to simplify code.
Themes
Mood
Type
When to use this quote
- API design
- client code
- error prevention
Key Concepts
Questions to Reflect On
- When could a null object cause hidden bugs?
- Is a null object always better than a null check?
Null objects can hide underlying design flaws.