Content deleted Content added
GTA5 GTA5 Khsunal GTA5 Khsunal GTA5 Khsunal 😎😎😎👑👑👑👑👑👑👑👑👑💔🎁🎁🎁🎁 Tags: Reverted Mobile edit Mobile web edit |
Reverting edit(s) by 2409:4041:2E07:8DBA:0:0:649:611 (talk) to rev. 1115203130 by NineLord: non-constructive (RW 16.1) |
||
Line 2:
{{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
'''Composition over inheritance''' (or '''composite reuse principle''') in [[object-oriented programming]] (OOP) is the principle that classes should achieve [[Polymorphism (computer science)|polymorphic]] behavior and [[code reuse]] by their [[object composition|composition]] (by containing instances of other classes that implement the desired functionality) rather than [[Inheritance (computer science)|inheritance]] from a base or parent class.<ref>{{cite book
| url = https://books.google.com/books?id=4pjbgVHzomsC&q=composite+reuse+principle&pg=PA17
Line 19 ⟶ 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 (program lifecycle phase)|runtime]].
==Example==
|