Friday, 31 May 2013

Null Object Pattern

Null Object Pattern

What is the category of Null Object Pattern?
Null Object Design Pattern comes under Behavioral patterns

What is Null Object Pattern?
Null Object Design Pattern is used to represent "Do Nothing" behavior.
It provides a Null Object as a surrogate object for the absence of an object of a given type.

This Null Object do nothing.

In Java SE 8, they have introduced a new class "java.util.Optional" to represent and handle "null" values and to avoid NullPointerExceptions.

Advantages of Null Object Pattern?

  • To avoid null checks and NullPointerExceptions
  • To avoid "if" block to check if that object is null or not