Class Cohesion (Single Responsibility Principle)
- Pretend you're talking to a sentient instance of your class. Pretend each of its methods is a question you're asking it. Do those questions all make sense? ("Mr. Gear, what is your tire size?" probably does not.)
- Describe the class's purpose in one sentence. If that sentence contains an "and" or an "or", it probably has more than one responsibility.
- Classes should call their own attribute reader and writer methods instead of reading and writing instance variables directly. (Controllers might be an acceptable exception to this rule.)
- Are there any complex data structures (2-dimensional arrays, etc.) that should be encapsulated in classes with named accessor methods?
- Are there any methods with more than one responsiblity? If you break them down into smaller methods, the new methods may be self-documenting (through their names) and may reveal additional beneficial refactorings.