Open Closed Principle (OCP): Theory and Implementation in Swift
Introduction to Open Close Principle Open-Closed Principle (OCP) is one of the principles in SOLID that was popularized by Uncle Bob. The idea originally comes from Bertrand Meyer in Object-Oriente...

Source: DEV Community
Introduction to Open Close Principle Open-Closed Principle (OCP) is one of the principles in SOLID that was popularized by Uncle Bob. The idea originally comes from Bertrand Meyer in Object-Oriented Software Construction (1988). In that book, Meyer defines this principle as: “Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.” What’s confusing about OCP The first thing I got from the title of this principle was we should try to predict how the code may grow from the start, so later it can be extended without modifying the existing code. So in my head, open sounded like “prepare the code so it can be extended later,” and closed sounded like “once the code is written, it should not be modified anymore.” From that interpretation, I ended up thinking that we should predicting future changes from the beginning, creating extension points early (hole), and then extending the code through those “holes” instead of modifying the exist