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

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.

主站蜘蛛池模板: 清涧县| 张掖市| 贵德县| 莱芜市| 封丘县| 遂昌县| 崇明县| 大丰市| 武陟县| 惠安县| 阿克苏市| 许昌市| 拜泉县| 财经| 讷河市| 桂林市| 灌云县| 奎屯市| 镇江市| 安塞县| 青田县| 邓州市| 厦门市| 长沙县| 青神县| 文山县| 潼关县| 景泰县| 游戏| 邯郸市| 瑞安市| 铜梁县| 湛江市| 红安县| 扶余县| 富平县| 玉林市| 平阴县| 嫩江县| 高尔夫| 万山特区|