开发者

Dummy implementation design pattern name

To avoid NullPointerExceptions I find it useful to provide an immutab开发者_JAVA技巧le 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?


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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜