1.

What do you understand by the Open-Closed Principle (OCP)?

Answer»

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.



Discussion

No Comment Found