I have a C# solution with this structure:
- Project 1: Contains a Dao (can contain more than one)
- Project 2: Contains an interface (only one)
-
Project 3: A wcf service with its own interface
-
The dao in project 1 implements the interface in project 2.
- The wcf service interface in project 3 implements/inherits/entends the interface in project 2.
The problem I have is that the interface in project 2 is needed to describe my dao class(s). The wcf interface is needed to describe what functions are available in my wcf service in project 3. The two interfaces are exactly the same, apart from the wcf attributes being on the wcf interface, because all the functions in the dao need to be exposed by the wcf service file too. The implementation or rather the dao class can be changed/swapped out but must always follow the same structure hence the need for an interface. Now with these two interfaces being identical when I try to implement it in my wcf interface I am told I must effectively override all of the methods in the interface I am deriving from. Is this the correct thing to do? The wcf interface needs to implement the interface from project 2 so that it provides all the functions we need from the dao (which is all of them).
Previously I had the project set up as follows:
- Project 1: Contains the dao
- Project 2: Contains an interface with wcf
attributes as well - Project 3: Contains no interface but just the wcf
service
Both the dao and the wcf service implemented the same interface from project 2. Would having the wcf attributes on the interface have had any adverse effects when using it with the dao? One issue I may have is that the wcf interface may eventually have extra functions that the base interface does not and so I think this previous structure would have been wrong. Truth be told I have no idea.
I know I am probably not explaining it very clearly and there are actually two or even three questions involved here but it is the best way to put it across. I guess my three main questions are as follows:
- Which inheritance/implementation structure would be best and why?
- Would implementing the same interface used by a wcf service in a
normal class have any ill effects (caused by the wcf attributes i.e. [ServiceContract], [OperationContract]). - Would overriding all of the methods provided by a base interface be
correct?
The structure you first defined is fine, you have an interface that implements an interface and the child interface can add new methods that aren’t in the base. However, you don’t need to define the base methods in the child interface because they are all inherited so right now your child interface would be empty. And in this model the child interface can have the WCF attributes.
Now, are you going to have to implement all of those methods in the WCF service? Quite simply yes because that’s what interfaces do – they define a contract that must be implemented.