The null object design pattern is relatively straightforward. It is a common task to check for null values during routine programming. We check for null so that we do not receive a null pointer exception from the Java Virtual Machine (JVM) at runtime.
The null object design pattern negates the need to search for the null condition. This is accomplished by creating a null object class. The null object class is designed to implement the same interface as other classes in the package. No functionality is included in the null object class.
We will look at an example use case, the UML class diagram, and the source code necessary to implement the null object design pattern for this scenario.