Chad
Chad

Reputation: 3227

Keeping Interfaces Separate

In my C# app I have several libraries. E.g:

My data access DLL, D, has an interface it exposes. Helper DLL B exposes another interface that has basically the same properties, but it's not the same interface (namespace wise and slightly with respect to how those properties are accessed). Furthermore, Helper DLL A uses what B and D expose. This is leading to confusion on my part as I need to connect B & D in A, but I find myself trying to convert between these interfaces and something doesn't seem right about it.

I'm confused as to what I should do:

  1. Use the data access interface from D across the whole app or...
  2. Have each DLL have separate interfaces and convert between them as they cross from one DLL to another.

Is there a preferred solution? If so, why?

Upvotes: 0

Views: 359

Answers (3)

tkerwood
tkerwood

Reputation: 1895

I would add another DLL with the interfaces that you want to use across the other three DLLs. Then any object that implements one of these interfaces will be able to be handled the same no matter of which DLL it was declared in. You can also extend any of these interfaces in one of the DLLS to include extra properties or methods where required.

Upvotes: 0

Tigran
Tigran

Reputation: 62246

If you need all that interfaces, it's diffcult to say to me just by reading your post, I would, personaly, suggest put them all in DataAccess and also conversion utilities too. So you will have all in one place and any Helper you'll write in the future will need to refer only that.

Upvotes: 1

Arafangion
Arafangion

Reputation: 11910

What's the problem? Can't you just make a class in main implement those interfaces as necessary?

Classes can inherit from more than one interface, or you can define various proxies that inherit from their respective class that operate on some common object instead.

Upvotes: 0

Related Questions