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

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.

主站蜘蛛池模板: 文安县| 万源市| 开远市| 德保县| 东安县| 靖远县| 德清县| 资溪县| 西充县| 贵定县| 凤冈县| 珠海市| 屏南县| 唐河县| 赞皇县| 城固县| 江北区| 淮阳县| 临猗县| 珲春市| 牡丹江市| 苏尼特左旗| 北辰区| 彝良县| 讷河市| 宝丰县| 维西| 阆中市| 晋城| 北碚区| 龙胜| 沽源县| 阳江市| 嘉义县| 惠东县| 二手房| 青田县| 遵义县| 沙田区| 阿图什市| 象山县|