可以有人以可靠的例子解释可插拔适配器的概念吗? [英] Can anybody explain the concept of pluggable adapter to me with good example?

查看:134
本文介绍了可以有人以可靠的例子解释可插拔适配器的概念吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以用很好的例子解释可插拔适配器的概念吗?

解决方案

从我从快速阅读中了解到的Google结果中,可插拔适配器是不适合特定适配器的适配器。在表面上(适配器自己的接口),它们都是一样的,但它可以适应不同接口的不同适配器。我发现



将其视为外星人;当它拥抱一张脸,你所看到的只是脸颊的粘糊糊的背面。你可以用棍子戳它,并试图撬开它的手臂(适配器接口)。但它基本上可以拥抱任何人(适应者)的脸,无论脸部特征如何。也许我推了一点,但是,嘿,我爱外星人。


Can anybody explain the concept of pluggable adapter to me with good example?

解决方案

From what I understood from a quick reading of Google results, a pluggable adapter is an adapter that isn't hard-coded against a specific adaptee. On the surface (the adapter's own interface), it's all the same but it can adapt to different adaptees with different interfaces. I found this thread pretty explanatory:

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.

And 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.

Think of it as a facehugger from Alien; when it hugs a face, all you see is the slimy back of the facehugger. You can poke it with a stick and try to pry off its arms (the adapter interface). But it basically can hug the face of any human (the adaptee), regardless of the face features. Maybe I'm pushing it a bit, but, hey, I love Alien.

这篇关于可以有人以可靠的例子解释可插拔适配器的概念吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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