- Design Patterns and Best Practices in Java
- Kamalmeet Singh Adrian Ianculescu LUCIAN PAUL TORJE
- 188字
- 2021-06-25 20:52:30
Open/closed principle
This principle is as follows:
"Modules, classes, and functions should be open for extension but closed for modifications."
Applying this principle will help us to develop complex and robust software. We must imagine the software we develop is building a complex structure. Once we finish a part of it, we should not modify it any more but build on top of it.
When developing software, it's the same. Once we have developed and tested a module, if we want to change it, we must test not only the functionality we are changing but the entire functionality it's responsible for. That involves a lot of additional resources, which might not have been estimated from the beginning, and also can bring additional risks. Changes in one module might affect functionality in others or on the whole. The following is a diagrammatic representation:

For this reason, best practice is to try to keep modules unchanged once finished and to add new functionality by extending them using inheritance and polymorphism. The open/closed principle is one of the most important design principles being the base for most of the design patterns.
- ThinkPHP 5實戰
- 少年輕松趣編程:用Scratch創作自己的小游戲
- Dependency Injection in .NET Core 2.0
- Learning ArcGIS Pro
- Python自然語言處理(微課版)
- Mastering Python Networking
- Swift細致入門與最佳實踐
- Learning Concurrent Programming in Scala
- Java實戰(第2版)
- Backbone.js Patterns and Best Practices
- ASP.NET jQuery Cookbook(Second Edition)
- Selenium Essentials
- Mastering VMware Horizon 6
- Drupal 7 Webform Cookbook
- OCaml語言編程基礎教程