❔ Creating a base abstract class to ensure a set of derived classes receive similar dependencies?
Hi, working on creating a class library and I have a set of classes, let's call them PlainPizza, PepperoniPizza and SausagePizza. These three need to have injected into them a set of similar dependencies by the DI container however beyond that they share no common methods.
Would it be advisable to have them inherit from a base abstract class that injects those dependencies while each derived class has its own interface that it implements such that unit testing is made easier?
7 Replies
No
Ah I see -- why not? What alternatives should I consider?
Using inheritance for code reuse is an anti pattern
None (regarding alternatives). Just let them be separate in terms of inheritance
Gotcha, will give that a shot then. Btw any suggested reading material for the inheritance anti pattern? Def want to read up on it
Thank you btw!
Basically any inheritance Vs composition blog
Ahhh ok
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.