I'm having a difficult time understanding the Single Responsibility Principle.
What should I look for to evaluate the various sources of information on the matter?
What should I look for in examples explaining the principle?
|
I'm having a difficult time understanding the What should I look for to evaluate the various sources of information on the matter? |
|||||||
|
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.
|
SRP is a fairly straight-forward principle.
-- http://en.wikipedia.org/wiki/Single_responsibility_principle
-- http://www.butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod Often, I find the second quote more applicable. I try to envision what my class does. What logic does it contain, or what external (to the class) services might it depend on. I try to think about what might change, and how might this cause my class to change. Are there multiple things that could change and affect my class? That is a code smell (but not always reason enough to split a class). Also, while I'm thinking along these lines, I look for cases where several classes will need to change if one other thing changes (logic, and external service, etc.). This too is a code smell. Often, though, I have small groups of tightly coupled classes that coordinate or interact to perform a single function or service. If the changes occur across this set of tightly coupled classes, I find that ok. But if a change in, say, an external service requires changes in multiple classes in different areas of my application, that is a stinkier code smell. |
||||
|
|
|
Pluralsight has a course Principles of Object Oriented Design that covers SRP as the first topic in about 12 minutes. I believe you get a couple of hours of video for free, after that you need a subscription. |
|||
|
|