<< back to blog

Is the SRP principle the same as "Low Coupling and High Cohesion"?

software

12 Jun, 2008

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...
Man makes nice software. Sells it. Makes $100,000 in 5 months
TODO.txt 2008 Ultimate Team Edition
Pretty Simple Software
Loose Coupling: Quote de jour
Cheap as Chips private Git hosting
Putting Git in the cloud with Amazon S3
Friendliest console installer EVER!
What Open Source stack do the gurus use?
Nice use of Google maps in registration
Generate State Machine diagrams from your POCO Entities

kick it on DotNetKicks.com
blog comments powered by Disqus