Home Segments Top Top Previous Next

758: Mainline

The key to the model–view approach is to keep models and views pure. No model is to know anything about information display, and no view is to know anything about any application domain. Thus, no model method is allowed to call a view-defined method or to access a view variable, and no view is allowed to call a model-defined method or to access a model variable.

Accordingly, you define a set of classes, whose only purpose is to enable mediation between model classes and view classes. The observers define methods that, for example, fetch information from model instances and relay that information to view instances. The listeners symmetrically define methods that, for example, fetch information from view instances and relay that information to model instances.

You learned about listeners in Segment 691. In particular, you learned how to use a window listener to shut down your application. In this chapter, you learn about listeners that have other responsibilities, such as fetching information from view instances and relaying that information to model instances.