What is the difference between listeners and adapters?

后端 未结 5 438
再見小時候
再見小時候 2021-02-02 11:07

I\'m trying to differentiate between listeners and adapters.

Are they pretty much the same but in listeners you have to implement all the methods in the interface, but w

5条回答
  •  悲哀的现实
    2021-02-02 12:10

    There is another aspect which is not addressed in other answers: API evolution. Providing adapter classes (a.k.a empty or default implementations of interfaces) makes introducing new methods in interfaces less painful. If an API provides only interfaces then clients are forced to implement them and if a new method is added to the interfaces then all implementing classes will break. However, if default implementations are provided then clients have the chance to extend those instead which, apart from being convenient, helps them upgrading to newer API version. With default methods of Java 8 default/empty implementation have become less important but they might be handy in older versions.

提交回复
热议问题