Generated by DeepSeek V3.2| Model–view–controller | |
|---|---|
| Name | Model–view–controller |
| Other names | MVC |
| Classification | Architectural pattern |
| Related patterns | Model–view–viewmodel, Model–view–presenter, Presentation–abstraction–control |
Model–view–controller. Model–view–controller is a fundamental architectural pattern commonly used for developing user interfaces that divides an application into three interconnected components. This separation of concerns facilitates efficient code management, parallel development, and enhanced testability. The pattern's influence is pervasive across numerous programming languages and application frameworks.
The core premise of the pattern is the isolation of domain logic, or the central model, from the user interface. This division allows developers and designers to work concurrently on components like the business logic and the graphical user interface with minimal interference. Originally conceptualized for desktop applications, the paradigm proved highly adaptable and was subsequently adopted for designing web applications. Its implementation is a cornerstone of many modern software engineering practices promoted by organizations like the Gang of Four.
The **Model** component directly manages the data, logic, and rules of the application, often interacting with a database management system like MySQL or PostgreSQL. The **View** component constitutes any representation of information, such as a chart, diagram, or HTML page, generated by frameworks like Angular. The **Controller** accepts input from the user via devices like a computer keyboard or touchscreen, converting it into commands for the model or view, acting as an intermediary as seen in platforms like Ruby on Rails.
A typical interaction cycle begins when a user triggers an event, such as clicking a button rendered by the View. This event is handled by the Controller, which may update the state of the Model, perhaps by executing a query on Microsoft SQL Server. Following a change, the Model notifies the View, often through an observer pattern, to update its display, a process streamlined in frameworks like ASP.NET. The Controller never directly describes the user interface, maintaining a clean separation.
Several derivative patterns have evolved to address specific challenges or contexts. The Model–view–presenter pattern, used in the Google Web Toolkit, introduces a presenter component to mediate more complex logic. The Model–view–viewmodel pattern, central to Microsoft's WPF and Silverlight, employs a viewmodel for robust data binding. Other adaptations include the Presentation–abstraction–control pattern and the Hierarchical model–view–controller utilized in the Cocoa and Cocoa Touch frameworks from Apple Inc..
The pattern's structure maps naturally to the request–response cycle of the World Wide Web, making it exceptionally popular for server-side web frameworks. Early adoption was championed by the Java-based Struts framework and later by Django for Python. The dominance of Ruby on Rails, which enforces a strict MVC convention, significantly popularized the approach. Contemporary JavaScript frameworks like Ember.js and Backbone.js also implement MVC or MVC-inspired architectures for client-side development.
The pattern was first described in 1979 by Trygve Reenskaug while working at the Xerox PARC research laboratory on the Smalltalk programming language. The initial concept was part of a project to make complex software, like the Dynabook vision, more manageable. The ideas were further refined and documented by other Xerox researchers, including Adele Goldberg. Its principles were later disseminated through influential texts like *Design Patterns: Elements of Reusable Object-Oriented Software* and became a standard feature in major frameworks from Sun Microsystems to Microsoft.
Category:Software design patterns Category:User interface techniques