The open-closed principle (OCP) says that software entities—classes, modules, and functions—should be open for extension but closed for modification. It is one of the SOLID principles used to make designs more flexible and maintainable. section 3.3 section 3.4
A practical approach is to introduce an abstraction that holds shared behavior, then add specialized implementations rather than repeatedly changing existing code. This keeps new needs localized while preserving the established model. section 3.3
Extending an asset model
An Asset parent class captures attributes shared by company assets. Hardware inherits from Asset, while future Software or Pitchfork subclasses can be added and treated as assets without altering the existing Hardware model. A DepreciationStrategy interface similarly supports swapping calculation approaches through concrete strategy implementations. section 3.3 section 3.3
Figure 3.5 We have added a depreciation strategy to our object model. This introduction allows us to swap out the method by which we can calculate the depreciation of an asset.
The class diagram makes the strategy interface and its concrete depreciation implementations visible, showing how a calculation method can be exchanged. section 3.3


