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.

Appendix G Eleva<strong>to</strong>r Events and Listener Interfaces (on CD) 1391<br />

1 // Eleva<strong>to</strong>rModelListener.java<br />

2 // Listener for Eleva<strong>to</strong>rView from Eleva<strong>to</strong>rModel<br />

3 package com.deitel.jhtp4.eleva<strong>to</strong>r.event;<br />

4<br />

5 // Eleva<strong>to</strong>rModelListener inherits all Listener interfaces<br />

6 public interface Eleva<strong>to</strong>rModelListener extends BellListener,<br />

7 But<strong>to</strong>nListener, DoorListener, Eleva<strong>to</strong>rMoveListener,<br />

8 LightListener, PersonMoveListener {<br />

9 }<br />

Fig. Fig. G.14 G.14 G.14 Interface Eleva<strong>to</strong>rModelListener allows the model <strong>to</strong> send all<br />

events <strong>to</strong> the view.<br />

G.4 Component Diagrams Revisited<br />

In Section 13.17, we introduced the component diagram for the eleva<strong>to</strong>r simulation. In our<br />

simulation, the Eleva<strong>to</strong>rView and every object in the model import package event.<br />

Figure G.15 presents the component diagram for package event. Each component in<br />

package event maps <strong>to</strong> a class from Fig. G.1–Fig. G.14. According <strong>to</strong> the component diagram,<br />

Eleva<strong>to</strong>rView.java of package view aggregates package event. In <strong>Java</strong>,<br />

this aggregation translates <strong>to</strong> class Eleva<strong>to</strong>rView importing package event. Also according<br />

<strong>to</strong> Fig. G.15, package model aggregates package event—i.e., each component<br />

in package model contains an aggregation with all components in pacckage event. (We<br />

show all components of package model in a separate component diagram in Appendix H.)<br />

In <strong>Java</strong>, this aggregation translates <strong>to</strong> each class in package model that imports ‘package<br />

event.<br />

This concludes the appendix on the events and listener interfaces of the eleva<strong>to</strong>r simulation.<br />

We hope you have found it a useful reference for the material on event handling<br />

discussed in “Thinking About Objects” Section 10.22. In the next two appendices, we<br />

implement the design for the model and the view, and we provide the component diagrams<br />

for packages model and view.

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

Saved successfully!

Ooh no, something went wrong!