Pattern:
Model-View-Controller


Author

Frank Buschmann, Regine Meunier, Hans Rohnert, Peter Sommerlad, and Michael Stal

Intent

"The Model-View-Controller architectural pattern (MVC) divides an interactive application into three components. The model contains the core functionality and data. Views display information to the user. Controllers handle user input. Views and controllers together comprise the user interface. A change-propagation mechanism ensures consistency between the user interface and the model." (Buschmann, F., R. Meunier, H. Rohnert, P. Sommerlad, and M. Stal. Pattern-Oriented Software Architecture: A System Of Patterns. West Sussex, England: John Wiley & Sons Ltd., 1996)

Motivation

MVC divides an interactive application into three areas: processing, output, and input. The model component encapsulates core data and functionality. The model is independent of specific output representations or input behavior. View components display information to the user. A view obtains the data from the model. There can be multiple views of the model. Each view has an associated controller component. Controllers receive input, usually as events that encode mouse movement, activation of mouse buttons, or keyboard input. Events are translated to service requests for the model or the view. The user interacts with the system solely through controllers. The separation of the model from view and controller components allows multiple views of the same model. If the user changes the model via the controller of one view all other views dependent o this data should reflect the changes. The model therefore notifies all views whenever its data changes. The views in turn retrieve new data from the model and update the displayed information. For a more detailed Motivation description for this pattern see: Buschmann, F., R. Meunier, H. Rohnert, P. Sommerlad, and M. Stal. Pattern-Oriented Software Architecture: A System Of Patterns. West Sussex, England: John Wiley & Sons Ltd., 1996.

Known Uses

This pattern has been used on the following systems: Smalltalk. This uses the MVC pattern in its user-interface framework. MVC is also used in Smalltalks VisualWorks. (LaLonde, W.R. and J.R. Pugh, Inside Smalltalk, Volume II, Prentice-Hall, 1991.) (Krasner, G.E. and S.T. Pope, A cookbook for using the Model-View-Controller user interface paradigm in Smalltalk-80, Journal of Object-Oriented Programming, 1(3), pp. 26-49, August/September 1988, SIGS Publications, New York, NY, USA, 1988.) MFC (Microsoft Foundation Class library). MFC integrates the Document-View variant of the MVC pattern in the Visual C++ environment. (Kruglinski, D., Inside Visual C++, Microsoft Press, 1995.) ET++. This application framework uses the Document-View variant. An ET++-based application will typically implement one document class and a corresponding view class. (Gamma, E., Objektorientierte Software-Entwicklung am Beispiel von ET++, Klassenbibliothek, Werkzeuge, Design, Dissertation, Universitat Zurich, 1991.)

See Also

Presentation-Abstraction-Control pattern

Thumbnail

Keywords

Model-View-Controller pattern, Presentation-Abstraction-Control pattern, Buschmann patterns, architectural patterns, interactive systems, user interface, multiple model views

Business Domains

interactive applications with a flexible human-computer interface

Problem Forces

changes to the user interface should be possible at runtimeneed a change propagation mechanism between the user interface and the modelneed multiple views of the functionality of the underlying applicationsystem may need to be ported to another platform with a different "look and feel"the display and behavior of the application must reflect data manipulations immediatelythe same information is presented differently in different windowsupgrades of windowing system requires changes to your systemuser interface is prone to change requests

Benefits

enhanced maintainability and extensibility of the systemexchangability of look and feelframework potentialmultiple views of the same modelpluggable views and controllersreusabilitysynchronized views

Liabilities

complexity of design and implementationdata transformation overheadobservers are unaware of each other - causing problems changing state of the subjectpotential for excessive number of updates

Implementation Files

Simple implementation of the pattern - Controller. Controller.javaSimple implementation of the pattern - View. View.javaSimple implementation of the pattern - Model. Model.javaSimple implementation of the pattern. mvc.h



Generated on Fri Oct 20 10:47:58 GMT+02:00 2000 by Framework Studio