111
Case Study: A Blackjack Example
Each card has its own face value (suit does not factor into the face value). Aces count as 1 or
11. Face cards (Jack, Queen, King) each count as 10. The rest of the cards represent their face
values.
The rules of the game state that if the sum of the face value of the player’s cards is closer to
21 than the sum of the face value of the dealer’s cards, the player wins an amount equal to the
bet that was made. If the player wins with a blackjack, the player wins 3:2 times the bet made
(assuming that the dealer does not also have blackjack). If the sum of the face value of the
player’s cards exceeds 21, the bet is lost. Blackjack (an ace and a face card or a 10) beats
other combinations of 21.
If the player and the dealer have identical scores and at least 17, it is considered a draw, and
the player retains the bet.
As already mentioned, you could also have presented the requirements in bullet form, as
we did for the DataBaseReader class in Chapter 2,“How to Think in Terms of Objects.”
We want to take the perspective of the user. Because we are not interested in the im-
plementation, we’ll concentrate on the interface.Think back to the black-box example
from Chapter 1,“Introduction to Object-Oriented Concepts.”We only care about what
the system does, not how it does it.
The next step is to study the requirements summary statement and start identifying the
classes. Before we actually start this process, let’s define how we are going to model and
track the classes that we ultimately identify.
Using CRC Cards
Discovering classes is not a trivial process. In the blackjack example we are working on,
there will be relatively few classes because this is intended as an example. However, in
most business systems, there could be dozens of classes—perhaps 100 or more.There must
be a way to keep track of the classes as well as their interactions. One of the most popular
methods for identifying and categorizing classes is to use class-responsibility-collaboration
cards (CRC). Each CRC card represents a single class’s data attributes, responsibilities, and
collaborations.
For me, one of the more endearing qualities of CRC cards is that they can be non-
electronic (although there are computer applications around that model CRC cards). In
their basic sense, CRC cards are, quite literally, a collection of standard index cards.
You need to create three sections on each card:
n
The name of the class
n
The responsibilities of the class
n
The collaborations of the class
The use of CRC cards conjures up scenes of dimly lit rooms—partially filled boxes of
pizza, pop cans, and multitudes of index cards strewn around the room.Although this
might be partially true, using CRC cards is a good technique because many of the people
involved with the design will not be developers.They might not even have much com-