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

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.

主站蜘蛛池模板: 莱芜市| 南部县| 犍为县| 城口县| 武鸣县| 绥宁县| 新昌县| 太康县| 紫云| 淮南市| 石台县| 隆林| 东安县| 临汾市| 灯塔市| 棋牌| 黎平县| 句容市| 拉萨市| 东海县| 西畴县| 旌德县| 长丰县| 萨嘎县| 林西县| 麻城市| 宜州市| 伊宁县| 手游| 海兴县| 克什克腾旗| 元阳县| 汉沽区| 修水县| 定陶县| 封开县| 平舆县| 远安县| 汪清县| 安新县| 女性|