Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to have over inheritance to be lost in code?

Tags:

c#

oop

asp.net

I'm currently working on an asp.net site, done by someone else, and it's rediculously over complicated for what it does......Well I think so! Pretty much every class inherits from another class then another and another and so on and on....... You have to go about 8/10 levels on average to get the the base class, sometimes more! And these classes have other classes inside which follow the same pattern of Uber Inheritence. This leaves me lost in code many many times resulting in God knows how many tabs open on visual studio.

Is this good/normal practice or is it bad practice? I feel it's bad practice as something so simple is made over complicated with an over usage of inheritance resulting in un-extensible code...............but I could be wrong :)

Thanks!

like image 293
Funky Avatar asked Feb 11 '11 14:02

Funky


2 Answers

Yes, over-using inheritance can lead to a spaghetti warehouse. Inheritance is a tool to allow for encapsulation and abstraction. Abusing it causes too much abstraction and then the purpose of the code becomes unusable. I've seen this pattern abused in imperative constructs as well where a method is passed from method to method to method before an action is actually applied.

private bool getData()
{
    return getOtherData();
}

private bool getOtherData()
{
    return getSomeExtraData();
} 

private bool getSomeExtraData()
{
    return SeeHowTediousThisIs();
}

It all works, but it's just an exceptionally bad architecture for maintenance. I find this often occurs with consultants/contractors attempting to introduce complexity (re: job security).

like image 189
Joel Etherton Avatar answered Oct 12 '22 14:10

Joel Etherton


There is a design guideline of 'favour composition over inheritance' 8-10 levels on inheritance breaks that somewhat.

http://en.wikipedia.org/wiki/Composition_over_inheritance

like image 32
Johnno Nolan Avatar answered Oct 12 '22 15:10

Johnno Nolan