Model-View-Controller architecture

Many web frameworks impose program architectures: it is difficult to provide wires to bind disparate components together without making some assumptions about what those components are. The Model-View-Controller (MVC) architecture is particularly popular on the Web, and it is the architecture the Play framework assumes. Let's look at each component in turn:

  • The model is the data underlying the application. For example, I expect the application underlying GitHub has models for users, repositories, organizations, pull requests and so on. In the Play framework, a model is often an instance of a case class. The core responsibility of the model is to remember the current state of the application.
  • Views are representations of a model or a set of models on the screen.
  • The controller handles client interactions, possibly changing the model. For instance, if you star a project on GitHub, the controller will update the relevant models. Controllers normally carry very little application state: remembering things is the job of the models.
    Model-View-Controller architecture

    MVC architecture: the state of the application is provided by the model. The view provides a visual representation of the model to the user, and the controller handles logic: what to do when the user presses a button or submits a form.

The MVC framework works well because it decouples the user interface from the underlying data and structures the flow of actions: a controller can update the model state or the view, a model can send signals to the view to tell it to update, and the view merely displays that information. The model carries no information related to the user interface. This separation of concerns results in an easier mental model of information flow, better encapsulation and greater testability.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.153.212