Java Reference
In-Depth Information
Exercise 14.5 Create physical CRC cards for the nouns/classes identified in this section, in
order to be able to work through the scenarios suggested by the project description.
Exercise 14.6 Do the same for any of your own extensions you wish to follow through in the
next stage.
14.2.3
Scenarios
The taxi company does not actually represent a very complex application. We shall find that
much of the total interaction in the system is explored by taking the fundamental scenario of
trying to satisfy a passenger request to go from one location in the city to another. In practice,
this single scenario will be broken down into a number of steps that are followed in sequence,
from the initial call to the final drop-off.
We have decided that a passenger source creates all new passenger objects for the system. So a
responsibility of PassengerSource is Create a Passenger , and a collaborator is Passenger .
The passenger source calls the taxi company to request a pickup for a passenger. We note
TaxiCompany as a collaborator of PassengerSource and add Request a pickup as a respon-
sibility. Correspondingly, we add to TaxiCompany a responsibility to Receive a pickup request .
Associated with the request will be a passenger and a pickup location. So TaxiCompany has
Passenger and Location as collaborators. When it calls the company with the request, the
passenger source could pass the passenger and pickup location as separate objects. However,
it is preferable to associate closely the pickup location with the passenger. So a collaborator of
Passenger is Location , and a responsibility will be Provide pickup location .
From where does the passenger's pickup location originate? The pickup location and desti-
nation could be decided when the Passenger is created. So add to PassengerSource the
responsibility Generate pickup and destination locations for a passenger , with Location
as a collaborator; and add to Passenger the responsibilities Receive pickup and destination
locations and Provide destination location .
On receipt of a request, the TaxiCompany has a responsibility to Schedule a vehicle . This
suggests that a further responsibility is Store a collection of vehicles , with Collection and
Vehicle as collaborators. Because the request might fail—there may be no vehicles free—a
success or failure indication should be returned to the passenger source.
There is no indication whether the company seeks to distinguish between taxis and shuttles
when scheduling, so we do not need to take that aspect into account here. However, a vehi-
cle can be scheduled only if it is free. This means that a responsibility of Vehicle will be
Indicate whether free .
When a free vehicle has been identified, it must be directed to the pickup location. TaxiCompany
has the responsibility Direct vehicle to pickup , with the corresponding responsibility in Vehicle
being Receive pickup location . Location is added as a collaborator of Vehicle .
On receipt of a pickup location, the behavior of taxis and shuttles may well differ. A taxi
will have been free only if it was not already on its way to either a pickup or a destination
 
Search WWH ::




Custom Search