NOTE

Open–Closed Principle

The open-closed principle favors extension without modifying existing code, reducing the risks introduced by maintenance changes.

Software Architecture & EngineeringCreated Updated 1 min readhistorical

This is a historical learning note and may contain outdated or incomplete understanding.

1. What Is the Open–Closed Principle?

Open for extension, closed for modification.

2. Why Is the Open–Closed Principle Needed?

Reduce new risks introduced by maintenance.

3. Implementing the Open–Closed Principle

When modifying code for a new requirement, check whether existing code needs to be modified. If so, refactor it: define an abstraction layer through interfaces or abstract classes, and encapsulate the aspects that may change in concrete implementation classes.

Inheritance: Liskov Substitution Principle.md

Composition/aggregation: Composition Reuse Principle.md

4. References

Discussion

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