I’ve been able to find great resources that tell me that MouseAdapter from the Java API doesn’t make use of the Adapter pattern. The question is: is there a pattern that MouseAdapter does implement?
I know what it does: it makes a concrete class for the MouseListener interface so you can just extend the class to avoid implementing unnecessary patterns.
I was thinking it may be part of the Bridge pattern. I’m not sure though, as I’m not familiar with this pattern.
Great question!
I can see why one responder stated Null Object as there are some conceptual similarities. I really like that answer. But in Null Object, it really is about removeing the need to continually check for null, as in:
And you do this by creating a stub object that overrides DoSomething() with a no-op implementation. The difference to me is that the intent is definiately different. If I see a Null Object (either in name or in docos) I expect that it should implemenet ALL operations with a no-op. I would never expect it a class to inherit from a Null Object. In fact, in my opinion, they should be sealed.
I don’t think Adapter is that bad, as the intent of Adapter is to adapt (change) an incompatible or ackward interface into a format that can be consumed or used. That is definitely the intent of the MouseAdapter. The MouseListener interface is indeed ackward, and MouseAdapter is converting that interface into something more easily consumable.
What does it adapt it into? I’d say the Template Method pattern. In particular, it converts interface implementation methods into “hook operations”. A hook operation is a method that exists to be overriden in a subclass, is generally implemented as a no-op, and is called by the base class. (Conceptually, I guess it is a Null Method instead of a Null Object). They exists as extension points, and that is how they are used in this case.