Single Responsibility Principle

A class should have only one reason to change.

When a class has more than one responsibility, then it is going to have more than one area to change. Moreover multiple responsibilities become tightly coupled. Changing one can affect the other. Modifying code for different reasons also increases the possibility of having more bugs in the code.

Another general concept closely related to Single Responsibility Principle is Cohesion. A high cohesive class has a set of related functions, where as a low cohesive class has a set of unrelated functions. A high cohesive class is more maintainable than a low cohesive one.

Cohesion is used as a measure of how closely a class or a module supports a Single Responsibility Principle.

Advertisements
Single Responsibility Principle

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s