What is the meaning and reasoning behind the Open/Closed Principle?

后端 未结 14 1186
死守一世寂寞
死守一世寂寞 2020-12-02 08:31

The Open/Closed Principle states that software entities (classes, modules, etc.) should be open for extension, but closed for modification. What does this mean, and why is i

14条回答
  •  既然无缘
    2020-12-02 09:00

    In Design principle, SOLID – the "O" in "SOLID" stands for the open/closed principle.

    Open Closed principle is a design principle which says that a class, modules and functions should be open for extension but closed for modification.

    This principle states that the design and writing of the code should be done in a way that new functionality should be added with minimum changes in the existing code (tested code). The design should be done in a way to allow the adding of new functionality as new classes, keeping as much as possible existing code unchanged.

    Benefit of Open Closed Design Principle:

    1. Application will be more robust because we are not changing already tested class.
    2. Flexible because we can easily accommodate new requirements.
    3. Easy to test and less error prone.

    My blog post on this:

    http://javaexplorer03.blogspot.in/2016/12/open-closed-design-principle.html

提交回复
热议问题