Model/view/controller (MVC) is a software architecture, currently considered an architectural pattern, used in software engineering.
The pattern isolates "domain logic" (the application logic for the user) from the user interface (input and presentation), permitting independent development, testing and maintenance of each (separation of concerns).
Use of the Model/View/Controller (MVC) pattern results in
applications that separate the different aspects of the application
(input logic, business logic, and UI logic), while providing a loose
coupling between these elements.
Though MVC comes in different flavors, control flow is generally as follows:
- The user interacts with the user interface in some way (for example, by pressing a mouse button).
- The controller handles the input event from the user interface, often via a registered handler or callback, and converts the event into an appropriate user action, understandable for the model.
- The controller notifies the model of the user action, possibly resulting in a change in the model's state. (For example, the controller updates the user's shopping cart)
- A view queries the model in order to generate an appropriate user interface (for example the view lists the shopping cart's contents). The view gets its own data from the model. In some implementations, the controller may issue a general instruction to the view to render itself. In others, the view is automatically notified by the model of changes in state (Observer) that require a screen update.
- The user interface waits for further user interactions, which restarts the control flow cycle.
The model manages the behavior and data of the application
domain, responds to requests for information about its state (usually
from the view), and responds to instructions to change state (usually
from the controller). In event-driven systems, the model notifies
observers (usually views) when the information changes so that they can
react.
The view renders the model into a form suitable for
interaction, typically a user interface element. Multiple views can
exist for a single model for different purposes. A view port typically
has a one to one correspondence with a display surface and knows how to
render to it.
The controller receives user input and initiates a response by
making calls on model objects. A controller accepts input from the user
and instructs the model and a view port to perform actions based on
that input.

Nessun commento:
Posta un commento