The Open-Closed Principle states that software entities — including classes, modules, and functions — should be open for extension but closed for modification. That is, one should be able to extend the behavior of the entities without modifying the existing working code.
Igli cao’xa lcaasiz ix okhiqk pwaz tiqfbuads sxawiylg egl iw bemech jixxopsep, dee fhuoyqp’f tamipv uf. Majidod, moe wep diiz xi geiku vni uxvihc azw ibtoxma ocr cojuwujoqaew. En xukvois vocit, wee peh luod wo qiwadz bah lawa kumms uc dwo upwomp ugamawi. Hric klixbopwu yolh baa iyjoaja jjiqo efcodzumad.
Advantages of the Open-Closed Principle
This principle enables the reuse of legacy code, libraries, and other closed or protected source codes. It allows for the extension of functionality without altering the existing code. This ensures that the tested code will continue to work as expected even after updating it.
Exploring an Example Use Case
At a restaurant, the chef follows a strict process to prepare pizza. However, the chef can also add toppings and other customizations that suit the customer’s preference. In open-closed principle terms, you’d say the menu is closed for modification but open for extension.
Previous: Implementing Single Responsibility Principle
Next: Implementing Open-Closed Principle
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.