Single Responsibility Principle

Have you heard about this before? Some of you might heard and an expert on this, and maybe some of you don’t know about this.

So, what is single responsibility principle?

The single responsibility principle is a computer programming principle that states that every module or class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility.
source :

S.R.P for short — this principle states that:

A class should have one and only one reason to change

It means a class should have only one job.

According to this principle, a class should not have multiple job like a swiss knife. Knife, screwdriver, pliers should be separated.

For example, you have a knife. knife used only to cut, if you want to pinning you should use pliers.

This principle prevents you to create an un-manageable class. If a class has a lot of job or responsibility, it’s easy to become a big class and a big class is hard to maintains.