开发者

WCF - separating service contracts and partial deriving?

So, I've seperated my WCF service contracts into discrete contracts for re-use.

I use to have IOneServiceContract that contained 3 functions: Function1, Function2, Function3.

I've seperated this service contract into two discrete service contracts: IServiceContract1 and IServiceContract2. IServiceContract1 contains Function1 and IServiceContract2 contains Function2 and Function3. This will开发者_如何学C allow me to re-use the discrete IServiceContract1 and/or IServiceContract2 to build a new service contract that represents the contract for the public service.

Knowing this...and hopefully I haven't messed up the description so that you can't follow the rest...

I have two services IService1 and IService2.

IService1 implements IServiceContract1 and IServiceContract2. This works perfect as IService1 needs to implement all of the functions: Function1, Function2, Function3.

IService2 however doesn't need to implement all of the functions of IServiceContract2, only Function1.

Is there a way for IService2 to partially implement the contract? I know that sounds ridiculous. Is the correct way to handle this situation to try and logically separate IServiceContract2 so that IService2 only has to implement the pieces that it needs?

Thanks


If you want to implement a service contract, you have to implement it all. That's why the "I" in the S.O.L.I.D. development principle is called "Interface Segregation Principle" : make your interfaces as small as possible so that an implementor doesn't have to implement a bunch of methods he really isn't interested in.

It seems you've basically embraced that principle - the question is: could you split up your methods in different way? Or would it hurt to split them up into three separate service contracts?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜