tl;dr Null Objects help avoid forcing clients to make explicit checks for null or undefined when obtaining an object from a container or collection. Null Object is related to the Optional or Option type found in many languages today, but there are differences, centering on whether the "null-ability" should be directly visible to the client or not.

Problem

Context

Solution

Some questions arise out of this:

Implementations

Consequences

A Null Object tends to lead to several consequences:

Variations

A couple of different takes on the Null Object include:

Last updated: 25 February 2022

Tags: pattern   behavioral