Resource

Null Object Design Pattern

Akkiraju Ivaturi Sep 10 2012
The null object pattern is a design pattern that simplifies the use of dependencies that can be undefined. This is achieved by using instances of a concrete class that implements a known interface, instead of null references.
    • Like
    • Love It
    • Awesome
    • Interesting
    • It's Okay
    • Thumbs Down
  • 3.3k
  • 0

The null object pattern is a design pattern that simplifies the use of dependencies that can be undefined. This is achieved by using instances of a concrete class that implements a known interface, instead of null references. 

"Unfortunately, using null tends to complicate the code." 

From the blog: 

"When you develop classes that have dependencies, you will sometimes have cases where a dependency is not needed, perhaps because the normal behaviour of the dependency is not required. One way to deal with such a situation is to use a null reference instead of a real object for that dependency. Unfortunately, using null tends to complicate the code. Wherever you need to use a member from the object, you must first check if it is null, as calling a method or accessing a property of a null reference will cause an exception." 

Continue reading here >>