Composition over inheritance: Difference between revisions

Content deleted Content added
Drawbacks: rm inappropriate italics; correct punctuation placement; prettify section link; flag up bare URLs
Tags: Mobile edit Mobile web edit Advanced mobile edit
Drawbacks: rm bare URLs template – already at the top of the seller
Tags: Mobile edit Mobile web edit Advanced mobile edit
Line 237:
 
==Drawbacks==
{{bare URLs|date=December 2022}}
One common drawback of using composition instead of inheritance is that methods being provided by individual components may have to be implemented in the derived type, even if they are only [[Forwarding (object-oriented programming)|forwarding methods]] (this is true in most programming languages, but not all; see {{section link|#Avoiding drawbacks}}). In contrast, inheritance does not require all of the base class's methods to be re-implemented within the derived class. Rather, the derived class only needs to implement (override) the methods having different behavior than the base class methods. This can require significantly less programming effort if the base class contains many methods providing default behavior and only a few of them need to be overridden within the derived class.