- Which design pattern follows Open Closed Principle?
- Why should the open closed principle be used when designing a class?
- How does obeying the Open Closed Principle improve the design of our code?
- Why is the Open Closed Principle OCP important?
Which design pattern follows Open Closed Principle?
For example, the Decorator pattern offers us to follow the Open Close principle. Furthermore, we may use the Factory Method, Strategy pattern and the Observer pattern to design an application with minimum changes in the existing code.
Why should the open closed principle be used when designing a class?
The general idea of this principle is great. It tells you to write your code so that you will be able to add new functionality without changing the existing code. That prevents situations in which a change to one of your classes also requires you to adapt all depending classes.
How does obeying the Open Closed Principle improve the design of our code?
The Open Closed Principle is a design principle that states that software components (such as classes and methods) should be open for extension but closed for modification. In other words, it means that you can add new functionality to your software without having to change the existing code.
Why is the Open Closed Principle OCP important?
In object-oriented programming, the open–closed principle (OCP) states "software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification"; that is, such an entity can allow its behaviour to be extended without modifying its source code.