I have in mind a set of classes which all will need to be instantiated
with some dependency object during construction. Consider these classes:
class A { A(IDependency dep) {...} }
class B { A(IDependency dep) {...} }
class C { A(IDependency dep) {...} }
class D { A(IDependency dep) {...} }
I want the DI to take place in the constructor, and obviously I want classes A,B,C,D to inherit from some abstract class or implement the same interface.
Problem: I can’t include the constructor in an interface or an abstract class.
What to do? Inherit from a non-abstract base class?
The base class doesn’t have a real meaning.
Use factory methods? Never really liked them…
Any suggestions?
Of course you can have a ctor in an abstract class.