Confusing use of adapter template in java.awt.event package and violation of interface separation principle (ISP)

Using patttern adapter in java.awt.event package seems confusing to me. On the one hand, this seems like a clear violation of the Interface Sharing Principle (ISP).

Like the class, MouseMotionAdapter implements MouseMotionListener, but provides a NIL implementation for both overridden methods.

Is this just about ISP violation? Following the ISP, MouseMotionListener will be split into two separate interfaces: one for moseDragged and moveMoved behavior?

Perhaps the separation of interfaces in this way will lead to a reduction in the number of interfaces and also make coding more inelegant, since for each implementation class it will be necessary to implement a large number of interfaces.

I just need to clarify whether my arguments are justified.

+4
source share
1 answer

This is not an ISP violation.

Short version: . You only think about the part of the system where you write your processing code. You do not think about where the events are generated (all in one place, the mouse monitoring code), and you do not think about the registration code for these events.

: , MouseEvent, , . Java , , , . MouseListener . , . . , MouseEvent, , , , Queue, instanceof.

, , MouseListener, , - , . , MouseAdapter , . { }.

0

All Articles