NOTE
Composition Reuse Principle
What the composition reuse principle is, why it is needed, and how composition or aggregation can be preferred over inheritance for code reuse.
This is a historical learning note and may contain outdated or incomplete understanding.
1. What Is the Composition Reuse Principle?
Use composition or aggregation relationships for code reuse whenever possible, and use inheritance less.
It is the embodiment of the open–closed principle in composition/aggregation.
2. Why Is the Composition Reuse Principle Needed?
Improve software reusability through composition.
3. Implementing the Composition Reuse Principle
Inject the new object as an attribute of the existing object.
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub