Home > Articles > Programming > Java

  • Print
  • + Share This
This chapter is from the book

Exploring Classes Using CRC Cards

Figure 3.3 shows the domain model we established in Chapter 2. The domain model enables us to explore domain or business objects. The user stories will enable us to discover the web-based user interface controller classes. So, let's look at coming up with objects for the Timesheet List user story next, to see exactly how CRC cards work.

03fig03.jpg

Figure 3.3 Domain model for Time Expression.

Figure 3.4 shows the Timesheet List UI prototype from Chapter 2. As I mentioned, we already know our user interface will be web based and will use the MVC paradigm. So, let's approach the discovery of our initial classes from the MVC perspective.

03fig04.jpg

Figure 3.4 Timesheet List screen.

On the model part of the MVC, we already know some entity names for Time Expression from our domain model. For the controller part, we know the user story tag (Timesheet List, in this example) from Chapter 2. Given these, we can now proceed with our initial class design using CRC cards.

In case you have been wondering, CRC stands for class, responsibilities, and collaborators. Table 3.1 shows the layout of a sample CRC card along with some explanations for the three components you see there. Note that although I have shown an electronic version, CRC cards can actually be done on basic 3" x 5" index cards and later translated into a class diagram (if needed).

Table 3.1. A Simple CRC Card Layout

Class Name (Noun)

Responsibilities (obligations of this class, such as business methods, exception handling, security methods, attributes/variables)

Collaborators (other classes required to provide a complete solution to a high-level requirement)

CRC cards provide an informal object-oriented technique for discovering interactions between classes. I like CRC cards because they can be used in an informal session with developers or users to discover objects without the need for a computer. Furthermore, CRC cards can be used to develop a formal class diagram, if needed (something we will do later in this chapter).

Tables 3.2 through 3.4 show some sample CRC cards for the actual classes we will develop later in this book, to meet the requirements for the Timesheet List screen.

Table 3.2. Sample CRC Card for Timesheet Class

Timesheet

 

Knows of period ending date

 

Knows of time

 

Knows of department code

 

Table 3.3. Sample CRC Card for TimesheetManager Class

TimesheetManager

 

Fetches timesheet(s) from database

Timesheet

Saves timesheet to database

 

Table 3.4. Sample CRC Card for TimesheetListController Class

TimesheetListController

 

Controller (in MVC) for displaying a list of timesheets

TimesheetManager

We just covered some basics about CRC cards. For now, we have a good enough idea of what we need to move forward with the next step.

  • + Share This
  • 🔖 Save To Your Account