views:

32

answers:

1

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 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

A: 

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?

marc_s
thank you...I was thinking that was probably the answer, just wanted extra confirmation i guess...I will take the methods and split them out then inherit from them in the class that currently contains both...that way the IServiceContract2 can just use the ones that is needed and IServiceContract1 can continue to inherit all...Thanks again for you answer...
dwhittenburg