Home Segments Top Top Previous Next

778: Mainline

The definition shown in Segment 777 illustrates all the key elements of the model–view approach: an application instance, a model, a view, an observer, and a listener.

As the constructor creates the movie model, it automatically connects that movie model to a new movie observer and then activates that new observer. The activated observer then looks for a meter view; if it finds that there is none, it creates one. Once the meter view is in hand, the observer fetches information from the movie model and relays that information to the meter view.

Later, in Chapter 46 and Chapter 49, you learn how to use list selection, button pushing, and typing to initiate a chain of calls that leads to calls to model setters. For now, to avoid further complexity, you see how to implement an illustrative listener that sets the movie script, acting, and direction variables to values that direct the meter pointer to any spot on the meter where you click your mouse.