我打算让一个核心模块公开接口,以便其他大模块(不同的客户端)进行通信.比方说,如果有一组方法:
void Method_A();
void Method_B();
void Method_X1();
Run Code Online (Sandbox Code Playgroud)
暴露给一种类型的客户端(模块"X1")和:
void Method_A();
void Method_B();
void Method_X2();
Run Code Online (Sandbox Code Playgroud)
暴露给其他类型的客户端(模块"X2")并知道Method_A并且Method_B应该具有确切的实现......那么我如何才能最好地设计服务架构(在服务和合同方面)?
有没有机会只实现一次Method_A和Method_B(在不同的合同实现中不是2次)?
使用WCF时,如何从界面继承中受益?
提前谢谢大家,如果我需要更清楚,请告诉我!
@marc_s ...我真的很感激你的观点......
类可以继承满足接口的方法,因此您可以拥有一个仅实现和 的IServiceBase接口和类,然后将独特的方法挑选到单独的接口中,最后将它们组合在继承并实现 Interface1 或 Interface2 的类中。例如:ServiceBaseMethod_AMethod_BServiceBase
[ServiceContract]
public interface IServiceBase
{
[OperationContract]
void Method_A();
[OperationContract]
void Method_B();
}
[ServiceContract]
public interface IService1 : IServiceBase
{
[OperationContract]
void Method_X1();
}
[ServiceContract]
public interface IService2 : IServiceBase
{
[OperationContract]
void Method_X2();
}
public abstract class ServiceBase : IServiceBase
{
void Method_A()
{
... implementation here ...
}
void Method_B()
{
... implementation here ...
}
}
public class Service1 : ServiceBase, IService1
{
void Method_X1()
{
... implementation here ...
}
}
public class Service2 : ServiceBase, IService2
{
void Method_X2()
{
... implementation here ...
}
}
Run Code Online (Sandbox Code Playgroud)