Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>My main assumption is that the most important thing is to maintain readability in domain part of the implementation. Therefore:</p> <ul> <li><p>If you have one behaviour and one possible implementation, then just don't create an interface:</p> <p>public class StackOverflowAnswerGenerator { }</p></li> <li><p>If you have one behaviour and many possible implementations, then there is no problem and you can just drop the "I", and have:</p> <p>public interface StackOverflowAnswerGenerator {}</p> <p>public class StupidStackOverflowAnswerGenerator : StackOverflowAnswerGenerator {}</p> <p>public class RandomStackOverflowAnswerGenerator : StackOverflowAnswerGenerator {}</p> <p>public class GoogleSearchStackoverflowAnswerGenerator : StackOverflowAnswerGenerator {}</p> <p>//...</p></li> <li><p>The real problem comes when you have one behaviour and one possible implementation but you need an interface to describe its behaviour (for example for convenient testing, because of convention in your project, using some library/framework which enforces this, ...). Possible solutions, other from prefixing the interface are:</p> <p><strong>a)</strong> Prefix or suffix the implementation (as stated in some other answers in this topic)</p> <p><strong>b)</strong> Use a different namespace for interface:</p> <p>namespace StackOverflowAnswerMachine.Interfaces { public interface StackOverflowAnswerGenerator {} }</p> <p>namespace StackOverflowAnswerMachine { public class StackOverflowAnswerGenerator : Interfaces.StackOverflowAnswerGenerator {} }</p> <p><strong>c)</strong> Use a different namespace for implementation:</p> <p>namespace StackOverflowAnswerMachine { public interface StackOverflowAnswerGenerator {} }</p> <p>namespace StackOverflowAnswerMachine.Implementations { public class StackOverflowAnswerGenerator : StackOverflowAnswerMachine.StackOverflowAnswerGenerator {} }</p></li> </ul> <p>Currently I'm experimenting with the last possibility. Note that in the implementation source file you can still have "using StackOverflowAnswerMachine;" and have convenient access to the domain objects.</p> <p><strong>UPDATE:</strong> Although I still think the last possibility is the cleanest, it's one drawback is that even though "using StackOverflowAnswerMachine;" gives you access to all domain objects you must prefix all domain interfaces not to be confused with their implementations. That may feel like something not very convenient but in clean design usually a class doesn't use many other domain objects, and mostly you need to use the prefix only in field declaration and constructor parameter list. So, that is my current recommendation.</p> <p>The client of domain functionality shouldn't need to know whether they're using an interface, an abstract class or a concrete class. If they need to know this, then there is some serious problem in such a project, because it has domain logic and infrastructural concerns mixed on the same abstraction layer. Therefore I recommend "<strong>a</strong>" or "<strong>c</strong>" solutions.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload