Is there any reason for an empty concrete method in an abstract class?

后端 未结 3 950
情深已故
情深已故 2021-01-05 18:34

I was recently looking through some open source code PicketLink code. If you take a look at this class, you\'ll see a number of concrete methods in an abstract class that d

3条回答
  •  旧巷少年郎
    2021-01-05 18:38

    Building off of Andres Fortier's answer, you will also see this pattern a lot in Swing, with the various EventListener Adapter classes. For example, MouseAdapter provides corresponding empty methods for each listener method. This allows the interface to define all relevant methods, but implementations to extend the corresponding adapter and only override a single method they care about, instead of being forced to provide empty bodies for all other interface methods.

提交回复
热议问题