3 ms·
I've seen C# interfaces and base classes that were committed years ago and never got a second implementation. This essentially makes the interface and base clas
by vsareto 6y ago
I've seen C# interfaces and base classes that were committed years ago and never got a second implementation. This essentially makes the interface and base class a pointless ritual in hindsight.
It's always easy to spot in hindsight, but TBH I think the threshold for creating interfaces or base classes should be a bit higher - likely when you know you will need 3 or more implementations. It's always felt like premature optimization to me, unless something is hard coded to only accept an interface like using Type.IsInterface or something.
Concepts like "Product" are almost always going to have multiple implementations though, so it's easy to judge in that case to make an interface/base class at the beginning. The real magic is guessing what other concepts satisfy this requirement.
- rickmode 6y agoI had this same belief but there is one other useful situation where an interface plus just one implementation class helps, and that's when you want to hide the noise of implementation details from another part of the program. This can happen between different layers of app. For example you might have a persistence layer under an API or UI, and want to expose a nice "clean" interface to the API / UI layer.
- Const-me 6y agoYes. To add to that, in C++ that approach often saves non-trivial amount of compilation time. Consumers of the object only need to #include the interface, while the implementation of the object, both code and data, stays private and is not needed to compile the consuming code.