CRC diagram -> “A responsibility is anything that a class knows or does”
a class should have a single purpose, collecting together a set of related sub-responsibilities
an index card with name, responsibilities, collaborators (dependencies).
Exercise
Let’s do some modeling. Create a skeleton for a simple Soccer league management system. This system tracks teams playing against one another, collecting points for victories, and ensuring equal playing schedules.
Create classes for the different objects you think are needed.
Create one class with many responsibilities
Create one class with many collaborators
Refactoring
Refactoring foreshadowing: pick one of the previous two classes, and make at least 2 classes out of it.
God Class
the class that does it all
common when moving from imperative languages or scripting
low cohesion - does many things, not connected
low coupling externally but now high coupling internally
look for classes with many many methods.
Naming
Surprisingly, one of the most important tasks developers have
Rely on naming conventions (yours, project, language, corporate)
Name classes to describe effects and purpose, not implementation
Naming
For example, in the HotDraw drawing framework, my first name for an object in a drawing was DrawingObject. Ward Cunningham came along with the typography metaphor: a drawing is like a printed, laid-out page. Graphical items on a page are figures, so the class became Figure. In the context of the metaphor, Figure is simultaneously shorter, richer, and more precise than DrawingObject.”
If a class is hard to name, it is probably doing too much.
Naming
Rate of change:
Things that change at the same rate belong together. Things that change at different rates belong apart. This principle is true of both the data manipulated by the program–two variables that always change at the same time belong in the same object–and the structure of the program–two functions that change at the same time belong in the same class.
“Empathy in naming” -> “if I searched for this function, what would I want it called?”