Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

The name (and javadocs) imply that MouseAdapter is an adapter (the design pattern). But I don't see it as such - it doesn't adapt anything to anything, at first sight at least

The only adaptation that happens is that you can pass an instance of MouseAdapter to any method that expects either of the interfaces. So, you make it possible to use a MouseListener instance where only MouseMotionListener is expected. But there is no "translation" happening. And it does not conform to the UML of GoF - in the "class adapter" version it is expected that a call to one method invokes a method from the adaptee.

So, is that an adapter (design pattern), or is it just a random name that causes confusion?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
228 views
Welcome To Ask or Share your Answers For Others

1 Answer

MouseAdapter first appeared in Java 1.1 released in Feb 1997. This means that it was developed sometime in 1996 (or 1995?)

UML (in its draft) was completed by 1997.

The first GoF book on design patterns was published in 1995.

So, I don't think that Adapter in MouseAdapter had anything to do with the corresponding design pattern. Or, even if it did, developers just had no unified language to express design patterns which would make it very hard to comprehend the real meaning.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...