Java Reference
In-Depth Information
location. So the responsibility of Taxi is Go to pickup location . In contrast, a shuttle has to
deal with multiple passengers. When it receives a pickup location, it may have to choose
between several possible alternative locations to head to next. So we add the responsibility
to Shuttle to Choose next target location , with a Collection collaborator to maintain the
set of possible target locations to choose from. The fact that a Vehicle moves between loca-
tions suggests that it has a responsibility to Maintain a current location .
On arrival at a pickup location, a Vehicle must Notify the company of pickup arrival , with
TaxiCompany as a collaborator; TaxiCompany must Receive notification of pickup arrival .
In real life, a taxi meets its passenger for the first time when it arrives at the pickup location,
so this is the natural point for the vehicle to receive its next passenger. In the model, it does
so from the company, which received it originally from the passenger source. TaxiCompany
responsibility: Pass passenger to vehicle ; Vehicle responsibility: Receive passenger , with
Passenger added as a collaborator to Vehicle .
The vehicle now requests the passenger's intended destination. Vehicle responsibility: Request
destination location ; Passenger responsibility: Provide destination location . Once again, at
this point the behavior of taxis and shuttles will differ. A Taxi will simply Go to passenger des-
tination . A shuttle will Add location to collection of target locations and choose the next one.
On arrival at a passenger's destination, a Vehicle has responsibilities to Offload passenger
and Notify the company of passenger arrival . The TaxiCompany must Receive notification
of passenger arrival .
The steps we have outlined represent the fundamental activity of the taxi company, repeated
over and over as each new passenger requests the service. An important point to note, however,
is that our computer model needs to be able to restart the sequence for each new passenger as
soon as each fresh request is received, even if a previous request has not yet run to comple-
tion. In other words, within a single step of the program, one vehicle could still be heading to
a pickup location while another could be arriving at a passenger's destination, and a new pas-
senger might be requesting a pickup.
Exercise 14.7 Review the problem description and the scenario we have worked through.
Are there any further scenarios that need to be addressed before we move on to class design?
Have we adequately covered what happens, for instance, if there is no vehicle available when a
request is received? Complete the scenario analysis if you feel there is more to be done.
Exercise 14.8 Do you feel that we have described the scenario at the correct level of detail?
For instance, have we included too little or too much detail in the discussion of the differences
between taxis and shuttles?
Exercise 14.9 Do you feel it is necessary to address how vehicles move between locations
at this stage?
Exercise 14.10 Do you think that a need for further classes will emerge as the application
is developed—classes that have no immediate reference in the problem description? If so, why
is this the case?
Search WWH ::

Custom Search