2011-06-30 96 views
0

我有一个软件与网站的API进行通信。我怎么能增加它的功能来连接到其他各种API,而无需触摸其中的代码?我认为最简单的方法是编写一个驻留在API和软件之间的代理,将来自其他API的传入消息转换为该软件“理解”的基本API。 我应该在哪里寻找更多关于使用c#实现这个代理的信息? 谢谢你的帮助。代理软件来增加其功能

回答

1

嗯听起来像你每天遇到的软件设计模式之一。我认为最适合你的“代理”实际上是桥梁。

sourcemaking

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

但是如果你只是想代理设计模式(这恕我直言,不适合您的问题)是列在这里:

  1. Proxy Pattern.
  2. Proxy Pattern in C#.

编辑:好的,对于更通用的解决方案,请使用代理模式并查看代理的现有实现。你会发现相当多的答案是回答问题,关于这个网站:

+0

嗨,答复表示感谢。我认为更多的是在本地机器上运行的真正的代理服务器来接收来自软件的通信(我没有提到太多,但又旧又复杂,是什么使得它更新非常耗时)并将这些消息翻译成其他API并连接与其他api。我发现这个:http://www.codeproject.com/KB/IP/mywebserver.aspx,并认为这可能是这个服务器的基础......我的推理是否正确? – Macin