Page 312 - Introduction to Programming with Java: A Problem Solving Approach
P. 312

                278 Chapter 7 Object-Oriented Programming—Additional Details
  GarageDoorDriver
  +main(args : String[]) : void
  GarageDoorSystem
  +GarageDoorSystem( ) +setState(state : int) : void +run(steps : int) : void
  Controller
  +Controller(system : GarageDoorSystem, state : int) +actionEvent() : void
  Switch
  +Switch(normallyOpen : boolean, control : Controller, use : String) +hit() : void
 Figure 7.21 First-cut UML diagram for Garage Door program
Apago PDF Enhancer
Figure 7.21 shows a first-cut Unified Modeling Language (UML) class diagram for the program. This first-cut diagram shows public methods but no instance variables or instance constants. Each of the driven classes contains a single constructor. Notice that each constructor is underlined. That conforms to UML standards, which suggest that you underline all constructors.
As usual, GarageDoorDriver has only a main method. Because we plan to do most of the con- trolling activities in the GarageDoorSystem class instead of in the driver class, that main method can be very simple. As you can see in Figure 7.22, our driver does just two things. It constructs a GarageDoorSystem object, and it runs a test on that object.
Notice that this driver does not construct any of the system’s components. It delegates that job to the GarageDoorSystem constructor. Since component construction probably depends on what the compo- nents are like, let’s look at those components next. Figure 7.23 contains the code for the controller.
As we wrote the code in Figure 7.23 we became aware of the need for several instance variables. They expand the UML class diagram for the Controller class to this:
 Controller
  -system : GarageDoorSystem -state : int
-motorDirection : boolean 􏰀 false;
 +Controller(system : GarageDoorSystem, state : int) +actionEvent() : void
 















































































   310   311   312   313   314