Open Closed Principle (OCP)

open closed principle in c#

The Open-Closed Principle is one of the five SOLID principles. It states that a class should be open for extension but closed for modification. In other words, you should be able to add new functionality without changing existing code.

Once you have written your class, it should not be modified in the future. However, this doesn’t mean you cannot modify your class during early development stages. It means that once your application or software is in production and you want to introduce the new functionality, you should extend that class rather than modifying it.

[Read More]

Single Responsibility Principle (SRP)

Single Responsibility Principle in c#

The Single Responsibility Principle (SRP) is a cornerstone of object-oriented design, closely associated with the SOLID principles. It emphasizes that a class should have only one reason to change, meaning it should have a single responsibility or purpose.

What is SRP?

The principle asserts that a class should do only one thing and do it very well. This doesn’t imply that a class should have only one method or behavior, but rather that it should contain a cohesive set of behaviors related to a single responsibility.

[Read More]