为什么MouseAdapter是适配器? [英] Why is MouseAdapter an adapter?

查看:72
本文介绍了为什么MouseAdapter是适配器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

名称(和javadocs)意味着 MouseAdapter 是适配器(设计模式)。但是我并没有看到这样的东西,它至少不适用于任何东西,一见钟情至少

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

唯一的改变就是你可以通过任何方法可以使用任何一种接口的方法来实现 MouseAdapter 。所以,您可以使用 MouseListener 实例,只需要 MouseMotionListener 。但是没有翻译发生。并且它不符合GoF的UML - 在类适配器版本中,预期对一种方法的调用将调用适配器的方法。

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?

推荐答案

MouseAdapter 首先出现在Java 1.1中,发布在 1997年2月。这意味着它是在1996年(或1995年)的某个时候开发的。

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

UML(在草案中)是 1997年完成

UML (in its draft) was completed by 1997.

第一本关于设计模式的GoF书是 1995年出版

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

所以,我不认为 MouseAdapter 中的适配器与相应的设计模式有任何关系。或者即使如此,开发人员也没有统一的语言来表达设计模式,这将很难理解真正的意义。

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.

这篇关于为什么MouseAdapter是适配器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆