【发布时间】:2011-06-30 18:37:25
【问题描述】:
我有一个与网站的 api 通信的软件。我怎样才能增加它的功能以连接到各种其他 api 而无需触及其中的代码?我认为最简单的方法是编写一个位于 api 和软件之间的代理,将来自其他 api 的传入消息转换为该软件“理解”的基本 api。 我应该在哪里查找有关使用 c# 实现此代理的更多信息? 谢谢你的帮助。
【问题讨论】:
我有一个与网站的 api 通信的软件。我怎样才能增加它的功能以连接到各种其他 api 而无需触及其中的代码?我认为最简单的方法是编写一个位于 api 和软件之间的代理,将来自其他 api 的传入消息转换为该软件“理解”的基本 api。 我应该在哪里查找有关使用 c# 实现此代理的更多信息? 谢谢你的帮助。
【问题讨论】:
嗯,听起来像是您每天都会遇到的软件设计模式之一。我认为最适合您的“代理”的实际上是桥接器。
Intent
- Decouple an abstraction from its implementation so that the two can vary independently.
- Publish interface in an inheritance hierarchy, and bury implementation in its own inheritance hierarchy.
- Beyond encapsulation, to insulation
Problem
“Hardening of the software arteries” has occurred by using subclassing of an abstract base class
to provide alternative implementations. This locks in compile-time binding between interface
and implementation. The abstraction and implementation cannot be independently extended or composed.
C#中的例子是http://sourcemaking.com/design_patterns/bridge/c%2523
但是,如果您只想在此处列出代理设计模式(恕我直言不适合您的问题):
编辑:好的,对于更通用的解决方案,使用代理模式并查看代理的现有实现。你会在这个网站上找到很多关于这个答案问题的答案:
【讨论】: