-2

The common tasks of web application framework(ex: Django or Laravel or .NET or beego):

request / response abstraction 
session state 
user authentication & authorisation 
page templating 
URL mapping 
DB access 
security 
caching

MVC design pattern implement above common tasks, as shown below:

  1. URL mapping is handled by Controller component of MVC. Controller routes requests to handlers. Ex: http.ServeMux is the controller from GOLang package

  2. request / response abstraction is performed by Controller by registering the handlers, written by web developer, as shown below:

    sm := http.NewServeMux()     // in GoLang
    
    sm.Handle("/", productHandler)
    
  3. session state is handled by the handler code written by web developer

  4. Page templating is handled by templating engine(view component) of MVC

  5. user authentication & authorisation is handled by the handler code written by web developer

  6. DB access is handled by model component of MVC.

  7. security and caching is handled by handler code written by web developer


Is this the right understanding on MVC design pattern to implement common tasks of web application framework?

overexchange
  • 15,768
  • 30
  • 152
  • 347

1 Answers1

1

There are many definitions of the MVC pattern. It was evolving over time and it was used differently in different frameworks and contexts. When it was invented, there was no HTTP protocol and the request/response part wasn't present. There were some other ways in which the user request was handled. With time, new template engines were invented and HTTP becomes dominant protocol on the web.

MVC is considered to be a pure presentation pattern since it mainly orchestrates views and model(whatever model is representing). Also, one of the main reasons why MVC is invented is separation of concern. It is important to keep it clean, short and to let other layers take care of logic.

The common task of the web application framework is to serve as IoC container (Inversion of control) and let its component worry about specific responsibilities. So if it is a web framework, it will probably have session, cookie, MVC... components.

  1. Controller methods are just an implementation of HTTP interface. URL Mapping can be considered as an argument to controller method.
  2. Request/response are handled by web component (servlet in Java)
  3. Session state is handled by session component and can be configured by developer e.g. session expire time or session cookie type or even session type (database, in memory)
  4. Correct
  5. Usually, there is a proven auth component in the framework, but it can be written manually (not recommended)
  6. DB access is handled by a persistence layer like JDBC in Java. Model in MVC is responsible for data that should be presented on the screen or submitted by the user.
  7. Same as 5
Miroslav Trninic
  • 3,327
  • 4
  • 28
  • 51