design patterns - DRY vs. "prefer containment over inheritance" -


A common rule of OO design is that you should have a model-use a relationship to use heritage and have a retainment / Aggregation and Forwarding / Delegation It is further compromised by Goef's advice that you should generally consider inheritance prevention, perhaps suggesting that, if you can make a strong case for any one in a particular situation, So stop it due to maintenance Education should inherited problems can sometimes be.

I understand the logic behind this thinking, and I do not disagree with it. However, when I look at a square with several methods, each just forwardes some frequency variables, then I see a form of code duplication. Code duplication, in my opinion, the final code is the odor to re-implement a huge protocol of the methods, because the relationship between the two classes is not strictly-it seems like a novel, it adds additional, unnecessary code , The code that is now required to be tested and documented as any other part of the system - if you have only inherited it probably has to write it.

The cost of adherence to the over-hereditary principal than this prevention is more than its benefits?

Virtually anything can be greater than its benefits After being hard and fast, no exception rules Always bother you with the development. In general, they are a bad idea to use it to use variables (if your language / runtime supports it) is not intended to be visible to your code. Is this a bad practice? With everything,

  It depends.  

What structure can sometimes be more flexible or easier to maintain with simplified heritage? Sure. This is the reason why it exists. In the same way, the heritage can be more flexible or easier to maintain than a pure structure architecture. After this you have the interface or (depending on multilingual language).

None of these concepts are bad, and people should be aware of the fact that sometimes our resistance to lack of understanding or change can be our reason to create arbitrary rules Whatever it does is to define "bad" without any real reason.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -