Después de investigar con especialistas en este tema, programadores de varias ramas y profesores hemos dado con la respuesta al problema y la compartimos en este post.
Ejemplo: herencia vs composición
Inheritance should only be used when:
Both classes are in the same logical domain
The subclass is a proper subtype of the superclass
The superclass’s implementation is necessary or appropriate for the subclass
The enhancements made by the subclass are primarily additive.
There are times when all of these things converge:
Higher-level domain modeling
Frameworks and framework extensions
Differential programming
If you’re not doing any of these things, you probably won’t need class inheritance very often.
The “preference” for composition is not a matter of “better”, it’s a question of “most appropriate” for your needs, in a specific context.
Hopefully these guidelines will help you out?
Más adelante puedes encontrar las notas de otros programadores, tú también eres capaz insertar el tuyo si te gusta.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)