Composition over inheritance: Difference between revisions

Content deleted Content added
Add banner {{Cleanup bare URLs}}. After at least 7 passes by @Citation bot since 20220821, this article still has 1 untagged bare URL ref
Line 1:
{{Short description|Software design pattern}}
{{Cleanup bare URLs|date=August 2022}}
{{Confusing|date=October 2015}}
[[File:UML diagram of composition over inheritance.svg|thumb|right|444px|This diagram shows how the fly and sound behavior of an animal can be designed in a flexible way by using the composition over inheritance design principle.<ref name="FHDPs" />]]
Line 17 ⟶ 18:
An implementation of composition over inheritance typically begins with the creation of various [[Interface (computing)#In object-oriented languages|interfaces]] representing the behaviors that the system must exhibit. Interfaces can facilitate [[Polymorphism (computer science)|polymorphic]] behavior. Classes implementing the identified interfaces are built and added to [[business ___domain]] classes as needed. Thus, system behaviors are realized without inheritance.
 
In fact, business ___domain classes may all be base classes without any inheritance at all. Alternative implementation of system behaviors is accomplished by providing another class that implements the desired behavior interface. A class that contains a reference to an interface can support implementations of the interface—a choice that can be delayed until [[Runtime_Runtime (program_lifecycle_phaseprogram lifecycle phase)|runtime]].
 
==Example==