Design pattern for default implementation with empty methods

前端 未结 9 1454
余生分开走
余生分开走 2021-02-02 11:32

Is there a specific design pattern that describes the scenario where a non-abstract default implementation is provided that implements all or some of the method

9条回答
  •  执笔经年
    2021-02-02 11:46

    There are no design patterns for default implementation.

    I usually append DoNothing prefix to the name of class. Depending on it's intent I use also Base or Default (the latter is widely used). Probably MouseAdapter should be called DefaultMouseListener.

    In the case you care, you can stub systematically an interface with a simple DynamicProxy, you must return only a "nice" default value (null for Object, 0 for numeric, etc).

    BTW this is a very good question.

    EDIT

    Furthermore this is neither a Stub or a Mock: maybe it can be confused with a Stub but the intent is different.

提交回复
热议问题