官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 金阳县| 金溪县| 蒙阴县| 鞍山市| 义马市| 华宁县| 环江| 汕尾市| 沙洋县| 城口县| 邹平县| 遂昌县| 寻甸| 和田市| 鹿泉市| 河曲县| 华池县| 炎陵县| 吉木萨尔县| 阿合奇县| 百色市| 井陉县| 南郑县| 嘉善县| 于田县| 瓦房店市| 儋州市| 阜新| 日照市| 陆丰市| 田东县| 武胜县| 灵寿县| 高阳县| 金坛市| 尤溪县| 沾益县| 温州市| 汉川市| 金寨县| 新宁县|