0 votes
in Design Patterns by
What do you understand by the Open-Closed Principle (OCP)?

1 Answer

0 votes
by

The Open close principle states that any class, component or entity should be open for extension but closed for modification. A class can be extended via Inheritance, Interfaces, Composition whenever required instead of modifying the code of the class. Consider an instance where we have a class that calculates the area of a square. Later, we get the requirement of calculating the area of a rectangle. Here, instead of modifying the original class, we can create one base class and this base class can be extended by the new class rectangle.

Related questions

0 votes
asked Oct 3, 2021 in Class-XI-PHYSICS by AdilsonLima
0 votes
asked Jun 24, 2020 in Azure by anonymous
...