SOLID – Single Responsibility Principle

Definition:

Every object should have a single responsibility, and that responsibility should be entirely encapsulated by the class.
In this principle the class should be only responsible for one thing or one task to do. responsible here means a reason to change, there must be never more than one reason to change your code ‘class’.

 The more responsibilities we have the more likelihood of change and the more changes affects the more errors will be introduced.

 In the SRP we want to strive for low coupling but high cohesion

 cohesion: Is the degree to which the elements of a module or class belong together.

 coupling: Is the degree to which each program module or class relies on each one of the other modules.

So Coupling talks about the inter-dependencies between the various modules while cohesion describes how related functions within a module are.

Continue reading