Answer the question
In order to leave comments, you need to log in
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
Inheritance describes the general behavior, interfaces describe the access method.
Here is an example https://github.com/vkorotenko/translit/blob/master...
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+? ;))
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 questionAsk a Question
731 491 924 answers to any question