我想将我的应用程序集成到X个外部系统中。与每个外部系统的集成将具有相同的操作类型,但将在一个单独的类中处理。
因此,目的是定义一个接口,以确保所有集成类都符合某些操作。例如:
public interface IOrderIntegration
{
//I want to define the ImportOrder action here, so that all future integrations conform
}但是,每个外部系统都有自己的封闭SDK (不能编辑),需要引用。e.g
public class EbayOrderIntegration : IOrderIntegration
{
void ImportOrder(Ebay.SDK.Order order)
{
//Logic to import Ebay's order
}
}
public class AmazonOrderIntegration : IOrderIntegration
{
void ImportOrder(Amazon.SDK.Order order)
{
//Logic to import Amazon's order
}
}在这种情况下,是否仍然可以使用接口来确保所有的集成都执行特定的操作?或者另一种模式?
发布于 2017-05-10 13:25:36
这就是仿制药出现的原因:
public interface IOrderIntegration<T>
{
void ImportOrder(T order);
}
public class EbayOrderIntegration : IOrderIntegration<Ebay.SDK.Order order>
{
void ImportOrder(Ebay.SDK.Order order order)
{
// ...
}
}发布于 2017-05-10 13:31:33
另一种方式比希姆布罗姆比尔的答案(顺便说一下,很棒的答案!)请注意,只有当您可以在订单级别进行抽象时,这才能起作用:
public class OrderIntegration
{
public void ImportOrder(IOrder order)
{
// Only possible if you can abstract all the logic into IOrder
}
}
public interface IOrder
{
// Abstract here the order logic
}
public class EbayOrder : IOrder
{
public EbayOrder(Ebay.SDK.Order order)
{ .. }
}
public class AmazonOrder : IOrder
{
public AmazonOrder(Amazon.SDK.Order order)
{ .. }
}在辛布罗姆比尔公司和我公司之间的选择将取决于你想去哪里(而且可以!)抽象不同的提供程序以及您希望如何使用API。
https://stackoverflow.com/questions/43893764
复制相似问题