BEST PRACTICES
A Best Practice for Designing Interfaces in .NET C#
Is it enough to define IMyInterface<T>? do I need IMyInterface as well?
While working on your masterpiece software system, you define your own interfaces to act as contracts between your different system modules and to expose some contracts to the outside world. This is not rocket science to any software developer.
However, what I learned throughout my years as a Software Engineer is that we should put more care about how we design our interfaces. If you search the internet, you would find tons of resources discussing the best practices to follow when designing interfaces, some of these are actually good resources.
But, I have one more best practice to tell you about which I couldn’t find online except for rare coincidences.
Is it enough to define IMyInterface<T>? do I need IMyInterface as well?
To answer this question, let’s walk through the example below step by step, so bear with me and don’t rush things out.
Disclaimer
We would not follow a lot of the best practices here for simplicity and to drive the main focus to the topic we are discussing. So, no unnecessary abstractions, no care for immutability,….and so on.
Main Entity Classes
These are the main entity classes we are going to use.