Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should interfaces "physically live"?

I like the idea of having Interfaces and Implementation separate. But how separate? Are the Interface definitions in a separate .Net assembly? Do you have a single project that defines all Interfaces for a solution? Otherwise are there issues with circular dependencies of Interfaces?

like image 293
Mike Schall Avatar asked Sep 11 '08 19:09

Mike Schall


3 Answers

Put your domain objects and interfaces in a seperate "domain" assembly.
This assembly should never reference anything but the core .net assemblies.

This way you get a clean seperation from your domain/service model and your implementation.

Edit:
http://jeffreypalermo.com/blog/the-onion-architecture-part-1/

like image 57
Lars Mæhlum Avatar answered Oct 04 '22 01:10

Lars Mæhlum


I wouldn't put the interfaces into a separate assembly just for the sake of it. However, if the interfaces take part in any form of IPC or extensibility architecture then it often makes sense to give them their own assembly.

If you have projects that need to reference each other, then yes, you will need a separate assembly for the interfaces, but you should also carefully examine architecture to see if there is another way of resolving the circular dependency.

like image 25
Rob Walker Avatar answered Oct 04 '22 02:10

Rob Walker


I prefer keeping the most common or simple implementations of the interface in a sub-folder (and namespace) following the name of the interface.

\project\
\project\IAppender.cs
\project\Appender\
\project\Appender\FileAppender.cs
\project\Appender\ConsoleAppender.cs

If I extend this class outside the project. In a special project, repeat the folders/namespace similarly.

\specialproject\
\specialproject\Appender\
\specialproject\Appender\MemoryAppender.cs
like image 33
Anthony Mastrean Avatar answered Oct 04 '22 01:10

Anthony Mastrean