Powers of Observation
By Al Williams
Both Smalltalk and C++, two common object oriented programming languages, provide architectures for creating multiple views of a single data source. In Smalltalk the architecture is called the Model-View-Controller (MVC). In the popular Microsoft Foundation Classes (MFC) for C++, it is known as the document-view architecture.
The idea is simple: Use one object to represent the data, and another object to represent a user's view of that data. For example, a spreadsheet document object stores numerical data and performs calculations on those numbers. The spreadsheet view object, on the other hand, knows how to present the classic grid and respond to user input.
Such an architecture has several advantages, especially for programs that have graphical user interfaces. With each view being described by an object, it's easy to spawn views in different windows, so that a user can have one window displaying a spreadsheet grid, and two windows displaying the same graph, and another displaying a chart. Also, your view objects can share a common library for visual operations like scrolling and splitting screens.
An Architecture for Java
To create an applet that gives a temperature reading in text and displays a graphical thermometer in a separate window, you can make use of Java's low-level support for building MVC-style programs. The java.util.Observer interface and the java.util.Observable class provides this support. The framework, however, is sparse and to make real use of it you have to do a bit of work.