Design pattern for default implementation with empty methods

前端 未结 9 1331
余生分开走
余生分开走 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 12:05

    It's also used in Swing (WindowAdapter, which implements WindowListener). It's only a convenience adapter, you only have to define 1-2 methods in this way to have a useful windowlistener. This is indeed an instance of the Adapter pattern, also shows the power of the abstract classes. It's even an example to illustrate why multiple implementation inheritance is useful sometimes.

    As for the regular Design Patterns, in the Temlate Method you can define hook operations, which may be overriden (unlike abstract methods, which must be), but the default behaviour (usually the NO-OP) is meaningful too.

提交回复
热议问题