开发者

Keeping Interfaces Separate

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

  • main app EXE
    • Helper DLL, A
    • Helper DLL, B
    • Helper DLL, C
    • Data access DLL, D

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. 开发者_JS百科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?


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜