Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • Thanks for this nice and informative answer. All methods of the awt adapter classes are empty including MouseAdapter. These empty methods may be innocent and acceptable. However, when you start to add code to these adapter methods, as noted at the post, things are getting messy. Commented May 24, 2020 at 9:45
  • This is not a composition vs. inheritance problem. If there wouldn't any code in adapter class (as in awt adapters), then I'll say yes you're right but there is code in the adapter (of discussed library). Let's think this way; awt developers added a new method named mouseJumped(event) and write some code on event object in this new method and assume that this code affects rest of the user code. For awt example, all methods takes isolated event objects, changing the event object doesn't affect the rest, such a nice design but the library that we're discussing, this isn't the case. Commented May 24, 2020 at 9:46
  • Creating a new interface or adding an empty method to a base class are both valid mechanisms to do this. If methods are not empty, this is a code smell, do you agree with me? Thanks again for information you gave. Commented May 24, 2020 at 9:46
  • Additionally, key events of awt adapter seem immutable which is a very nice design. If a user stores this object anywhere, this doesn't harm to anyone. Commented May 24, 2020 at 11:40
  • 1
    It does seem odd for a notification interface to include code in the base class. If this is code that the library requires to function properly, then the developer of the library runs the risk that the client never calls the base method. Commented May 24, 2020 at 19:48