47.6k views
2 votes
Where might the Null Object pattern be useful?

User Jamier
by
6.5k points

1 Answer

4 votes

Answer: Null Object pattern be useful when the absence of an object can be encapsulated by other alternatives which does not have any have any effect.

Step-by-step explanation:

public interface Rectangle {

double area();

double surfaceare();

boolean isNull();

}

In the code above we have a function for null object. So in the absence of an object we have encapsulated with a method of null which does not do anything. It simplifies the use of dependencies that can be undefined.

In case of collaborator the NULL object pattern makes use of the existing collaboration instead of defining a new one.

It also enable to abstract the handling of null objects from the client so that internal details of the program are not know to outsiders.

User Salomon BRYS
by
7.3k points