Single Responsibility Principle

Pamal Jayawickrama
2 min readMar 7, 2021

SRP is the first principle in SOLID principles. SOLID principle contain such as

S-single Responsibility Principle

O-open-closed Principle

L-liskov substitution Principle

I-interface segregation Principle

D-dependency inversion Principle

Benefit of SOLID Principle

when we go more depth in to this principles we will come to know that how it will more benefit or how it going to be helpful when you are software grows. So I listed some of the benefits of SOLID principle in the bellow.

Loose-Coupling

Code Maintainability

Dependency Management

Single Responsibility Principle

A class should have one and only one reason to change, meaning that a class should have only one job

it means that class should have only one responsibility not more than one. You can understand this with the following example,

look at this example, first two methods are related to the class properties but the last method is not like. So we have to implement separate class for it.

look at the following example.

That’s what single responsibility principle is. I hope that you will understand this.

--

--