Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composition, how do you know when to stop? [closed]

There's the old but wise saying "Value composition over inheritance". I've been trying to apply this, along with other OOPs and Design-Patterns, for the last couple of projects that I've been involved in.

For most of the cases, it has worked fine and looked kind of right. But I've noticed that some times, there are just 2 or 3 classes that really get the best out of it, while other 10+ classes suddenly become kind of simple delegators with minor changing details.

Sometimes, I try to fix this by using an abstract class with the unvarying details that delegates the varying ones to the concrete implementations, but something doesn't feel completely right about it.

How do you keep balance of this and follow the old wise saying at the same time? Am I doing something wrong?

like image 361
Edgar Gonzalez Avatar asked Apr 19 '11 01:04

Edgar Gonzalez


1 Answers

I think your problem may be that you are trying to follow the "old wise saying". You probably know much better the requirements of the application than any generic guidelines.

Once you have gathered some experience building applications, you should get a natural feel for how to do things. The guides are just that, guides to help you understand a concept. They are not rules in itself.

like image 137
Elias Mårtenson Avatar answered Nov 09 '22 09:11

Elias Mårtenson