Chapter 6 Methods 295 (Top ten web hosting) From the ring the
Chapter 6 Methods 295 From the ring the elevator bell phrase listed with class Elevator, we conclude that class Bellshould have an operation that provides a service namely, ringing. We list the ringBell operation under class Bell. When arriving at a floor, the elevator signals its arrival to the doors. The elevator door responds by opening, as implied by the phrase opens [the elevator s] door associated with class Elevator. Therefore, class ElevatorDoor needs an operation that opens its door. We place the openDoor operation in the bottom compartment of this class. The phrase closes [the elevator s] door indicates that class ElevatorDoor needs an operation that closes its door, so we place the closeDoor operation in the same compartment. Class ElevatorShaftlists turns off light and turns on light in its verb-phrases column, so we create the turnOffLight and turnOnLight operations and list them under class Light. The resets floor button phrase implies that the elevator instructs a floor button to reset. Therefore, class FloorButton needs a resetButton operation. The phrase walks on floor listed by class Person is not an operation, because a person decides to walk across the floor in response to that person s creation. However, the phrases presses floor button and presses elevator button are operations pertaining to the button classes. We therefore place the pressButton operation under classes Floor- Button and ElevatorButton in our class diagram (Fig. 6.21). The phrase rides elevator implies that Elevator needs a method that allows a person to ride the elevator, so we place operation ride in the bottom compartment of Elevator. The enters elevator and exits elevator phrases listed with class Person suggest that class Elevator needs operations that correspond to these actions.1 We place operations enterElevator and exitElevator in the bottom compartment of class Elevator. The requests elevator phrase listed under class FloorButton implies that class Elevator needs a requestElevator operation. The phrase signals elevator to move to opposite floor listed with class ElevatorButton implies that Elevator- Button informs Elevator to depart. Therefore, the Elevator needs to provide a departure service; we place a departElevatoroperation in the bottom compartment of Elevator. The phrases listed with classes FloorDoor and ElevatorDoor mention that the doors by opening signal a Person object to enter or exit the elevator. Specifically, a door informs a person that the door has opened. (The person then enters or exits the elevator, accordingly.) We place the doorOpened operation in the bottom compartment for class Person. In addition, the ElevatorDoor opens and closes the FloorDoor, so we assign openDoor and closeDoor to the bottom compartment of class FloorDoor. Lastly, the creates person action associated with class ElevatorModel refers to creating a Person object and adding it to the simulation. Although we can require ElevatorModel to send a create person and an add person message, an object of class Person cannot respond to these messages, because that object does not yet exist. We discuss new objects when we consider implementation in Chapter 8. We place the operation addPerson in the bottom compartment of ElevatorModel in the class diagram of Fig. 6.21 and anticipate that the application user will invoke this operation. 1. At this point, we can only guess what these operations do. For example, perhaps these operations model real-world elevators, some of which have sensors that detect when passengers enter and exit. For now, we simply list these operations. We will discover what, if any, actions these operations perform as we continue our design process. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/3/01