Design Patterns Null Object Pattern - Design Patterns

What is Design Patterns Null Object Pattern?

In Null Object pattern, a null object replaces check of NULL object instance. In its place of putting if check for a null value, Null Object reflects a do not anything relationship. Such Null object can also be used to provide default behaviour in case data is not accessible.

In Null Object pattern, we construct an abstract class specify different operations to be done, concrete classes extending this class and a null object class provide do nothing implementation of this class and will be used seamlessly where we need to verify null value.


We are going to produce conceptual Customer conceptual class essential operations. Here the name of the customer and concrete classes extending the Abstract Customer class. A factory class Customer Factory is produced to return either Real Customer or Null Customer objects based on the name of client passed to it.
NullPatternDemo, our demo class, will use Customer Factory to show the use of Null Object pattern.

Step 1

Create an abstract class.

Step 2

Create concrete classes extending the above class.

Step 3

Create Customer Factory Class.

Step 4

Use the Customer Factory to get each Real Customer or Null Customer substance based on the name of client passed to it.

Step 5

Verify the output.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

Design Patterns Topics