dimanche 28 février 2016

Ways to implement Null Object Pattern

Till now I have seen everywhere that the steps to create Null Object Pattern, for example in BST to remove null checks, are as follows:

  1. Create an interface Node

  2. Create two classes implementing the interface Node. One of which will be real_Node and other will be null_Node.

  3. Using those classes, null checks can be removed in BST class while creating the tree.

Now I want to know that, are there other ways to do this, e.g., Can we implement Null Object Pattern without interface using only classes, i.e. in the above step (1.) can we use Node class instead of Node interface

Aucun commentaire:

Enregistrer un commentaire