任何人都可以用很好的例子向我解释可插拔适配器的概念吗?
最佳答案
从我对 Google 结果的快速阅读中了解到,可插拔适配器是一种没有针对特定适配器进行硬编码的适配器。表面上看(适配器自己的接口(interface)),都是一样的,但它可以适应不同的适配器,不同的接口(interface)。我找到了this thread很好解释:
Basically, it allows you to put in an adapter when the adaptee (receiver) protocol is not known at compile time by using reflection. When you create the adapter instance, you pass it the name of the adaptee's method to call, and also any metadata that's necessary to translate input types. When the adapter receives a method call of the target interface, it uses reflection to call the corresponding method specified on the adaptee.
和this :
The main responsibility of the Viewer is to populate a widget from a domain model without making any assumptions about domain itself. JFace viewer uses the Delegating Objects mechanism in Pluggable Adapter Pattern to implement the above requirement.
把它想象成来自 Alien 的脸拥抱者;当它拥抱一张脸时,你所看到的只是它粘糊糊的背部。你可以用一根棍子戳它,然后试着 pry 开它的 ARM (适配器接口(interface))。但它基本上可以拥抱任何人(适应者)的脸,无论面部特征如何。也许我有点过分了,但是,嘿,我爱外星人。
关于language-agnostic - 任何人都可以用很好的例子向我解释可插拔适配器的概念吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/449424/