适配器模式如何工作?
我最近在学期课程中读到了有关适配器模式的内容。我已经理解了提供通用接口以便第三方API可以在我们的系统中工作的概念。
但是它在编码中如何工作,假设我有两个第三方 SDK,例如:
A(String name)
A1(String Firstname,String Lastname)
现在我生成称为 IAAdapater
的通用接口。现在编写代码,现在我的问题是,如何通过 IAdapater 调用 A(String name)
或 A1(String Firstname,String Lastname)
?
如果我错了请纠正我!
I recently read about Adapter pattern in my semester course. I have understood the concept of providing the common interface so that the third party APIs can work in our system.
But how does it will work in coding, lets say that i have two third party SDK, such as:
A(String name)
A1(String Firstname,String Lastname)
Now i produce the common interface called as, say, IAAdapater
. And now write the code in that, now my question is, how does one call A(String name)
or A1(String Firstname,String Lastname)
through IAAdapater
?
Correct me if I'm wrong!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑我认为另一个答案更接近您正在寻找的内容 - 我实际上在这里描述了一个外观。
您的 IAAdapter 需要公开方法 A(String name) 和 A1(String Firstname, String Lastname)
然后您需要一个委托给底层对象的接口的实现。
Edit I think the other answer is closer to what you are looking for - Im actually describing a Facade here.
Your IAAdapter needs to expose the methods A(String name) and A1(String Firstname, String Lastname)
You then need an implementation of this interface that delegates to the underlying objects.
现在您只需担心一个 API:名字、姓氏。不同的适配器将处理其余的事情。
如果我误解了这个问题,请告诉我。
Now you only have to worry about one API: firstname, lastname. The different adapters will handle the rest.
Please let me know if I misunderstood the question.