Composition over inheritance: Difference between revisions

Content deleted Content added
Update broken link to project lombok delegate feature.
Composition and interfaces: rm inappropriate quotation marks, replace with link
Tags: Mobile edit Mobile web edit Advanced mobile edit
Line 78:
 
===Composition and interfaces===
The C++ examples in this section demonstrate the principle of using composition and interfaces to achieve code reuse and polymorphism. Due to the C++ language not having a dedicated keyword to declare interfaces, the following C++ example uses "inheritance from a pure [[abstract base class"]]. For most purposes, this is functionally equivalent to the interfaces provided in other languages, such as Java and C#.
 
Introduce an abstract class named {{code|VisibilityDelegate}}, with the subclasses {{code|NotVisible}} and {{code|Visible}}, which provides a means of drawing an object: