The principle of shared responsibility and separation of problems are one and the same.
Of course, you can get bogged down in an academic discussion, trying to figure out some difference between them, but why? In all senses and purposes they describe the same thing. The biggest problem is that people are so passionate that they want to know exactly what “care” and “responsibility” is, that they may be missing the important idea behind SRP and SoC.
The idea is to simply break your codebase into loosely coupled isolated parts. This allows several developers to work in different areas without affecting each other, and also allows one developer to modify one isolated part without disturbing the other.
This is applied at the module level, for example MVC is an architectural template promoting SRP and SoC. The code base is divided into isolated models, views, and controllers. Thus, a change of view can be made regardless of the model. Two two are not terribly intertwined.
At a lower level, this should also apply to classes. Instead of introducing dozens of methods into one class, split the code into several. For the same reasons.
Also, even at the method level, break large methods into smaller methods.
Basically. SRP is a principle, not a rule, so you do not need to (read: I can not / should not) follow it to the extreme. This does not mean that going too far and having only one method of seven lines in each class, for example. It just means the general principle of dividing code into separate parts. The fact is that this will lead to a better code base and more stable software.
Weyland Yutani Jul 29 '14 at 9:37 a.m. 2014-07-29 09:37
source share