#inheritance chaining
1 messages · Page 1 of 1 (latest)
When your question is answered use !solved or the button below to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
Not necessarily.
In really really big and old codebases it could be, but that doesn’t mean it’s good or recommended.
You should prefer composition over inheritance wherever possible.
That being said, it’s not every deep inheritance that’s bad. As always, it depends on the context and the problem in hand that’s being solved.
Gotcha. Composition as in composition and aggregation right
as in, instead of your class inheriting other classes, you should design it in such a way that it uses other classes instances as data members.
Eg.
class Type : public Type2
{…};
// vs
class Type
{
Type2 obj;
};
Okay I see
Just making sure I understand them correctly.
Composition is where a class has another class and owns it
Aggregation is where a class has another class but doesn’t own it(holds a pointer)
Would you say aggregation is less common? Or just depends on the context
Entirely depends on context
Sounds good!
more often you will be decryping classes with inheritance written by some senior dev 15 years ago who left the company, and intelisense aint gonna do anything, so you will need to dectypt all existing base classes and all existing derived classes from that base
😭sounds like a headache lol
nah it's ez
forcefully insert a compile error like, rename some class from
ValueBase to ValueBaseFake
and watch as the compielr spits out all occurences of ValueBase saying "ValueBase not found, did you mean ValueBaseFake?"