NOTE

Composition Reuse Principle

Composite reuse favors composition or aggregation over inheritance. These notes examine code reuse and extension through that principle.

Software Architecture & EngineeringCreated Updated 1 min readhistorical

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 applies the open–closed principle to 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.

4. References

Discussion

Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub