Check out the new USENIX Web site. next up previous
Next: The Displayer-View pattern Up: Architectural patterns Previous: Architectural patterns

The Model-View pattern

 

Model-view is a derivation of Smalltalk's model-view-controller (MVC) architecture; the model-view derivation combines MVC's view and controller into a single abstraction [2]. In Tycho, we have implemented a Model class that provides a publish-and-subscribe mechanism, unbounded history, a simple but flexible external structured file format called TIM (Tycho Information Models), and a simple serialization mechanism. Its subclasses implement application-specific models, such as storing user preferences, information about classes used by the documentation generator and class browser, indexes into the file system, and so on. There are also a set of graph classes which, although currently written in Itcl, we hope to eventually have written in Java.

Models are based on TIM (Tycho Information Models), which is a meta-data format that is intended to encourage clean representations of data, both in in-memory objects and in an external file representation. It is loosely based on the concepts of Object Modeling Technique (OMT) [14]: a model is a collection of entities and links between entities. Each entity and link has a unique name, value, and a list of attributes. Entities can be nested, so TIM is naturally hierarchical. A small TIM (for a dataflow graph) is:

    vertex a {
        port out -tokencount 2 -type output
    }
    vertex b {
        port in-0
        port in-1
        port out -type output
    }
    edge a out b in-0 -initialdelay 0

Models contain a straight-forward implementation of the publish-and-subscribe pattern (also known as the Observer pattern [5]): any view that is interested in a model can subscribe to it, and will be notified of any updates to the model. The prototype graph editor in figure 3, for example, has two models: one for the graph, and one for the canvas layout. We have demonstrated multiple views editing the same two models. The concept is pervasive throughout Tycho: all major widgets, for example, are subscribed to the user preferences model. When a user changes, say, the font used in menu buttons, all menus are automatically updated with the new font.

Because user interfaces typically allow a user to undo and redo operations, Model implements a reasonably flexible, unbounded, undo and redo mechanism. Each method that changes a model is required to return a script that will undo the change. Both the method call and arguments and the undo script are stored in linear arrays.


next up previous
Next: The Displayer-View pattern Up: Architectural patterns Previous: Architectural patterns