C
C
ChernovGV2019-12-29 10:57:10
OOP
ChernovGV, 2019-12-29 10:57:10

OOP folks, when is the right time to use inheritance over composition?

Hello!
3 years ago, after disappointment in inheritance, I switched to using composition + interfaces. I am satisfied, but, nevertheless, I want to reconsider my radical views on this paradigm.
Tell me, when is it right to use inheritance instead of composition?
Thank you!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladimir Korotenko, 2019-12-29
@firedragon

Inheritance describes the general behavior, interfaces describe the access method.
Here is an example https://github.com/vkorotenko/translit/blob/master...

#
#, 2019-12-29
@mindtester

advice - do not bother. when exactly you need a class hierarchy with inheritance. you will feel it

3 years ago, after disappointment in inheritance..
Does that mean the total experience is definitely at least 3+? ;))
.. I'm generally more and more drawn to the functional paradigm. but in sharpe it is somehow almost all within LINQ .. I look at F #))
the transition is not a transition, but the combination can definitely give interesting results))

D
Daniel Demidko, 2020-12-30
@DanielDemidko

The Gang of Four recommends that composition be preferred by default. Inheritance is heavily overrated. In most cases, even the interface is not needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question