Jun 12, 2008 / software
Is the SRP principle the same as "Low Coupling and High Cohesion"?

I was thinking about the Single Responsibility Principle - which roughly states that a class should only be responsible for one thing. (Is the word responsibility deliberately vague do you think!?)

Back in the software degree, we were taught that we should aim for Low Coupling and High Cohesion.

Basically, our units of code (classes and functions) should depend on as few other things as possible. This is low coupling.

To achieve high cohesion, we should keep related things together, so that code can be changed in as few places as possible.

I think that SRP is based on these principles. If an class has one responsibility, then it's cohesive because the code in that class focuses on a restricted set of purposes. If a class focuses on a restricted set of purposes, then it shouldn't need to be coupled to too many other things.

Conversely, if a class has many responsibilities then there is a good chance it will need to collaborate with lots of other classes (high coupling), and that it will contain code for lots of different things (low cohesion).

Thoughts?


You may also like...