Aryan
Aryan

Reputation: 1

Design Issues with Inheritance Implementation

Initial Situation:- I had 20 different classes, one each containing code to provide feed to each downstream system, so 20 classes for 20 systems. No I hire a architect to simplify my code.

Architect suggested applying OOP principles that we should use inheritance and move common functionality to base class and use is a relationship with 20 classes.

Problem:- This increased my testability efforts, earlier we had separate code for each downstream so need to regress with one system only but now for any change in base class, we need to test with 20 systems, so applying OOP's created more problems.

What should be the design to solve this problem?

Upvotes: 0

Views: 64

Answers (1)

Robert Bräutigam
Robert Bräutigam

Reputation: 7744

In short, you can try to use composition instead of inheritance. This might result in a more stable downstream-specific object which then doesn't need to be tested when common things change. Depending on your exact case this may or may not help, but is a sensible alternative at least.

Obviously we don't know your exact circumstances. In general inheritance is really problematic and should be avoided if possible.

A bit more specifically, inheriting from a baseclass to share code (I'm assuming this is your case, I don't know for sure) is also not a good practice. So strike two for inheritance.

Composition involves creating a useful abstraction for the common things. Basically a standalone object or objects that do something useful, but not downstream specific. Then using those objects in the downstream-specific objects, instead of inheriting any of it.

Upvotes: 1

Related Questions