C
C#2y ago
Irae

❔ 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
phaseshift
phaseshift2y ago
No
Irae
IraeOP2y ago
Ah I see -- why not? What alternatives should I consider?
phaseshift
phaseshift2y ago
Using inheritance for code reuse is an anti pattern None (regarding alternatives). Just let them be separate in terms of inheritance
Irae
IraeOP2y ago
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!
phaseshift
phaseshift2y ago
Basically any inheritance Vs composition blog
Irae
IraeOP2y ago
Ahhh ok
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server