Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dummy implementation design pattern name

To avoid NullPointerExceptions I find it useful to provide an immutable dummy implementation of an interface together with the interface. Like this:

public interface Action {

  void perform();

  public static final Action dummy = new Action() {
    public void perform() { 
      /*nothing*/ 
    }
  };

}

Action.dummy can then be used instead of the evil null.

Is there a name for this design pattern?

like image 459
deamon Avatar asked Jul 21 '10 22:07

deamon


1 Answers

Null Object pattern (provided by M. Fowler if I remember correctly).

Here is a chapter Introduce Null Object from Fowler's Refactoring book.

like image 161
Roman Avatar answered Sep 21 '22 15:09

Roman