26.07.2013 Views

Java How to Program Fourth Edition - DCC

Java How to Program Fourth Edition - DCC

Java How to Program Fourth Edition - DCC

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

704 Graphical User Interface Components: Part 1 Chapter 12<br />

draw and transfer funds). A person is an external entity that can play the part of a Bank-<br />

Cus<strong>to</strong>mer. In the same manner as an object is an instance of a class, a person playing the<br />

part of a BankCus<strong>to</strong>mer performing one of its roles (such as making a deposit) is an<br />

instance of ac<strong>to</strong>r BankCus<strong>to</strong>mer. For example, when a person named Mary plays the<br />

part of a BankCus<strong>to</strong>mer making a deposit, Mary—in the role of the deposi<strong>to</strong>r—becomes<br />

an instance of ac<strong>to</strong>r BankCus<strong>to</strong>mer. Later in that day, another person named Jon can be<br />

another instance of ac<strong>to</strong>r BankCus<strong>to</strong>mer. In the course of a day, several hundred people<br />

might use the ATM machine—some are “deposi<strong>to</strong>rs”, some are “withdrawers” and some<br />

are “transferrers,” but all of these people are instances of ac<strong>to</strong>r BankCus<strong>to</strong>mer.<br />

The problem statement in our eleva<strong>to</strong>r simulation supplies the ac<strong>to</strong>rs—“The user<br />

requires the ability <strong>to</strong> create a person in the simulation and situate that person on a given<br />

floor.” Therefore, the ac<strong>to</strong>r of our system is the user who controls the simulation (i.e., the<br />

user who clicks the but<strong>to</strong>ns <strong>to</strong> create new Persons in the simulation). An external entity—<br />

a real person—plays the part of the user <strong>to</strong> control the simulation. In our system, the use<br />

case is “Create Person,” which encompasses creating a Person object, then placing that<br />

Person on either the first or second Floor. Figure 12.28 models one ac<strong>to</strong>r called “User.”<br />

The ac<strong>to</strong>r’s name appears underneath the ac<strong>to</strong>r.<br />

The system box (i.e., the enclosing rectangle in the figure) contains the use cases for<br />

the system. Notice that the box is labeled “Eleva<strong>to</strong>r Simulation.” This title shows that this<br />

use-case model focuses on the one use case that our simulation provides <strong>to</strong> users (i.e.,<br />

“Create Person”). The UML models each use case as an oval. The system box for a system<br />

with multiple use cases would have one oval per use case.<br />

There is a reasonable alternate view of the use case of our eleva<strong>to</strong>r simulation. The<br />

problem statement from Section 2.9 mentioned that the company requested the eleva<strong>to</strong>r<br />

simulation <strong>to</strong> “determine whether the eleva<strong>to</strong>r will meet the company’s needs.” We are<br />

designing a simulation of a real-world scenario—the Person object in the simulation represents<br />

an actual human being using an actual eleva<strong>to</strong>r. Thus, we may view the user of the<br />

eleva<strong>to</strong>r simulation as the user of the eleva<strong>to</strong>r. Therefore, specifying a use case from the<br />

Person object’s perspective helps model how a real person uses a real eleva<strong>to</strong>r system.<br />

We offer the use case of Fig. 12.29, titled “Relocate Person.” This use case describes the<br />

Person moving (relocating) <strong>to</strong> the other Floor. (The Person travels <strong>to</strong> the second<br />

Floor if starting on the first Floor and <strong>to</strong> the first Floor if starting on the second<br />

Floor.) This use case encompasses all actions that the Person performs along his or her<br />

journey, such as walking across a Floor <strong>to</strong> the Eleva<strong>to</strong>r, pressing But<strong>to</strong>ns and riding<br />

the Eleva<strong>to</strong>r <strong>to</strong> the other Floor.<br />

User<br />

Eleva<strong>to</strong>r Simulation<br />

Create Person<br />

Fig. Fig. 12.28 12.28 Use-case diagram for eleva<strong>to</strong>r simulation from user’s perspective.<br />

© Copyright 1992–2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!