Skip to content

Latest commit

 

History

History

1. Single Responsibility Principle

Some important points for SRP

  • Cohesion:- Higher cohesion helps better adherence to the SRP
  • Coupling:- It is defined as the level of inter dependency between the software components. Loose coupling helps better adherence to SRP.
  • Every software component should have one and only one reason to change. Otherwise, more changes will lead to more bugs which also lead to more testing

Code

  1. Low cohesion functions calculateArea/calculatePerimeter and draw/rotate are belonged to same type i.e. Square Code-not-following-SRP
  2. Now the overall cohesion increase as we separate out the functions Code-following-SRP
  3. Tight coupling between the Student and DB. So in future if we want change the DB then it will lead to change in Student functionality. Code-not-following-SRP
  4. Loose coupling between the Student and DB. So in future if we want to change the DB then it will not lead to change in Student functionality. Code-following-SRP