C
C#16mo 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
phaseshift16mo ago
No
Irae
Irae16mo ago
Ah I see -- why not? What alternatives should I consider?
phaseshift
phaseshift16mo ago
Using inheritance for code reuse is an anti pattern None (regarding alternatives). Just let them be separate in terms of inheritance
Irae
Irae16mo 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
phaseshift16mo ago
Basically any inheritance Vs composition blog
Irae
Irae16mo ago
Ahhh ok
Accord
Accord16mo 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
More Posts