Java Reference
In-Depth Information
We start with a simple example scenario:
A customer calls the cinema and wants to make a reservation for two seats tonight to
watch the classic movie
The Shawshank Redemption.
The cinema employee starts using
the booking system to find and reserve a seat.
Because the human user interacts with the booking system (represented by the
Cinema
BookingSystem
class), this is where the scenario starts. Here is what might happen next:
■
The user (the cinema employee) wants to find all showings of
The Shawshank Redemption
that are on tonight. So we can note on the
CinemaBookingSystem
CRC card, as a responsi-
bility:
Can find shows by title and day
. We can also record class
Show
as a collaborator.
■
We have to ask ourselves: How does the system find the show? Who does it ask? One solu-
tion might be that the
CinemaBookingSystem
stores a collection of shows. This gives us an
additional class: the collection. (This might be implemented later by using an
ArrayList
, a
LinkedList
, a
HashSet
, or some other form of collection. We can make that decision later;
for now, we just note this as a
Collection
.) This is an example of how we might introduce
additional classes during the playing of scenarios. It might happen every now and then that
we have to add classes for implementation reasons that we initially overlooked. We add to
the responsibilities of the
CinemaBookingSystem
card:
Stores collection of shows
. And we
add
Collection
to the collaborators.
Exercise 13.3
Make a CRC card for the newly identified
Collection
class, and add it to
your system.
■
We assume that three shows come up: one at 5:30 p.m., one at 9:00 p.m., and one at 11:30
p.m. The employee informs the customer of the times, and the customer chooses the one at
9:00 p.m. So the employee wants to check the details of that show (whether it is sold out,
which theater it runs at, etc.). Thus, in our system, the
CinemaBookingSystem
must be able
to retrieve and display the show's details. Play this through. The person playing the booking
system should ask the person playing the show to tell them the required details. Then you
note on the card for
CinemaBookingSystem
:
Retrieves and displays show details
, and on
the
Show
card you write:
Provides details about theater and number of free seats
.
■
Assume that there are plenty of free seats. The customer chooses seats 13 and 14 in row
12. The employee makes that reservation. We note on the
CinemaBookingSystem
card:
Accepts seat reservations from user
.
■
We now have to play through exactly how the seat reservation works. A seat reservation is
clearly attached to a particular show, so the
CinemaBookingSystem
should probably tell
the show about the reservation; it delegates the actual task of making the reservation to the
Show
object. We can note for the
Show
class:
Can reserve seats
. (You may have noticed that
the notion of objects and classes is blurred when playing through CRC scenarios. In effect,
the person representing a class is representing its instances too. This is intentional and not
usually a problem.)
■
Now it is the
Show
class's turn. It has received a request to reserve a seat. What exactly does
it do? To be able to store seat reservations, it must have a representation of the seats in the
Search WWH ::
Custom Search