SOLID – Open/Closed Principle


it states that the software entities (classes, modules, functions,..etc.) should be open for extension but closed for modification.

in this principle we want to be able to add a new behavior ‘open to extension’. without the need to change our source or binary code ‘closed to modification’. or in other words we should strive to write code that doesn’t have to be changed every time the requirements change.

huh! change behavior without changing the code. !!

Yes we can achieve this by relying on abstraction (Interfaces, Abstract Base Classes) because there is no limit to number of different ways we can implement that abstraction .

An Example :

Suppose that there is a class called Rectangle that has a width and height properties within it.


Continue reading