Chapter 3 Introduction to Java Applets 137 (Top web site)

Chapter 3 Introduction to Java Applets 137 model elevator shaft elevator person floor (first floor, second floor) elevator door floor door elevator button floor button bell light These categories are likely to be classes we will need to implement our system. Notice that we create one category for the buttons on the floors and one category for the button on the elevator. The two types of buttons perform different duties in our simulation the buttons on the floors summon the elevator, and the button in the elevator informs the elevator to move to the other floor. We can now model the classes in our system based on the categories we created. By convention, we capitalize class names in the design process (as we will do when we write the actual Java program that implements our design). If the name of a class contains more than one word, we run the words together and capitalize each word (e.g., Multiple- WordName). Using this convention, we create classes ElevatorModel,3 Elevator- Shaft, Elevator, Person, Floor, ElevatorDoor, FloorDoor, ElevatorButton, FloorButton, Bell and Light. We construct our system using all of these classes as building blocks. Before we begin building the system, however, we must gain a better understanding of how the classes relate to one another. Class Diagrams The UML enables us to model, via the class diagram, the classes in the elevator system and their interrelationships. Class diagrams model the structure of the system by providing the classes, or building blocks, of the system. Figure 3.20 represents class Elevator using the UML. In a class diagram, each class is modeled as a rectangle. We then divide this rectangle into three parts. The top part contains the name of the class. The middle part contains the class attributes. (We discuss attributes in Thinking About Objects Section 4.14 and Section 5.11.) The bottom part of the rectangle contains the class operations (discussed in Thinking About Objects, Section 6.17). 3. When we refer to the elevator model, we imply all classes composing the model describing the operation of our elevator system in other words, in our simulation, several classes comprise the model. We will see in Section 13.17 that our system requires a single class to represent the model we create class ElevatorModel to act as the representative for the model, because, as we will see in Fig. 3.23, ElevatorModel is the class that aggregates all other classes comprising the model. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/2/01

Leave a Reply