O'Reilly logo

Prefactoring by Ken Pugh

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

4.3. The Initial Design

Everyone has their own way of coming up with an initial set of classes. You can start with the basic abstractions that were described during analysis. Some people examine the requirements or use cases for nouns, and turn those nouns into either classes or attributes of classes. Verbs that occur can be turned into responsibilities or methods of the classes. One ambiguity that exists in using grammatical syntax to discover objects is that an operation might be expressed as either a noun or a verb. The requirements might talk about a customer renting a CD or starting a CD rental.

Tim and I use a variation of CRC cards (see Object Design: Roles, Responsibilities, and Collaborations by Rebecca Wirfs-Brock and Alan McKean [Addison-Wesley Professional, 2002]) to formulate a starting set of classes.[*] CRC stands for Class-Responsibility-Collaboration. On an index card, you list the class name, the responsibilities assigned to the class, and the other classes that it collaborates with to fulfill those responsibilities. Tim and I also jot a one-line description of each class on the card. Often we also capture potential attributes or other information that might have been referred to in the use cases or client discussions. Figure 4-2 depicts the CRC cards for Sam's CD rental system.

[*] See also http://c2.com/doc/oopsla89/paper.html.

Figure 4-2. CRC cards for Sam's CD rental system

Tim and I often code class interfaces directly from the CRC cards. But since ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required