Home Segments Top Top Previous Next

Chapter 42:

How to Define Standalone Observers and Listeners

The MovieApplication definition shown in Segment 781 contains a locally defined observer and two locally defined listeners. One benefit of local definition is that the observer and listener code is readily located. Another benefit is that the methods of the locally defined classes can employ MovieApplication instance methods. For example, the observer employs the getMovie and getMeter methods.

When you design practical applications, however, the benefit of having everything in one place can become the burden of having too much in one place, and you find yourself more inclined to define your observers and listeners separately.

In this chapter, you learn how standalone observers and listeners can access the required application instance methods.