The Null Object Pattern

Learn about the null object pattern.

The null object pattern is an idea that relates to the good practices that were previously studied. Here, we are formalizing them, and giving more context and analysis to this idea.

How does the null object pattern work

The principle is rather simple—functions or methods must return objects of a consistent type. If this is guaranteed, then clients of our code can use the objects that are returned with polymorphism, without having to run extra checks on them.

Get hands-on with 1400+ tech skills courses.