Principle#2(OCP)

 

*The open-closed principle (OCP):-
We can declare it as
(classes should be open for extension and closed for modification).
This all about allowing change,but doing it without requiring you to modify existing code.

??dont understand right 😀
Close for modification:—->you close classes by not allowing anyone to touch your working code.
Open for extension:——->you open classes by allowing them to be subclasses and extended.

Example:-
If We define a super class and in it define a method That doesn’t change on this class,Then in sub class you override it then your super class is closed for modification but it is open for extension as the subclass change the behavior of this method.

Posted in OOD

Leave a comment