Single Responsibility Principle

The class should have only one reason to change.

This principle overcomes the below drawbacks-

If the class has more than one reason to change,
  1. Change in one area impacts the other.
  2. This makes the code more fragile (easily to break).
  3. Difficult to test and maintain.
  4. Tight coupling.
  5. Less cohesive (a class has many action) and hence not focusing on what it is suppose to do.
Hence, Single responsibility boils down to high cohesion i.e. a class focus on what it should be doing (methods related to the intention of class)  

Comments

Popular posts from this blog

@Overrride annotation introduced in Java1.5

Liskov Substitution Principle (LSP)

Interface Segregation Principle