language-agnostic - 任何人都可以用很好的例子向我解释可插拔适配器的概念吗?

标签 language-agnostic design-patterns adapter

任何人都可以用很好的例子向我解释可插拔适配器的概念吗?

最佳答案

从我对 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.



Facehugger in action

把它想象成来自 Alien 的脸拥抱者;当它拥抱一张脸时,你所看到的只是它粘糊糊的背部。你可以用一根棍子戳它,然后试着 pry 开它的 ARM (适配器接口(interface))。但它基本上可以拥抱任何人(适应者)的脸,无论面部特征如何。也许我有点过分了,但是,嘿,我爱外星人。

关于language-agnostic - 任何人都可以用很好的例子向我解释可插拔适配器的概念吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/449424/

相关文章:

android - 监听器上的适配器支架不能是最终的

language-agnostic - 用矩阵变换3D向量的方法

optimization - 算法 - 找到两个数组之和之间的最小减法

design-patterns - 设计模式 - 服务层

ruby - 如何在 Ruby 中实现查找类?

android - 在 Listview 和 BaseAdapter 中设置可见性的问题

c# - 用于在字符串列表 C# 中查找字符串匹配的最佳比较算法

language-agnostic - 我想编写一个没有使用入口障碍的工具。我必须用C写吗?

c++ - 动画管理器设计模式?

java - 适配器类出现问题,没有崩溃,但页面卡住并重新加载