MVC Notes - fcrimins/fcrimins.github.io GitHub Wiki

MVC components

  • Model = data structure
  • DAO = data operations
  • View = display
  • Controller = tie everything together

Relationship between Model (in MVC) and DAO

  • In the Model-View-Controller design pattern, the Model represents business logic and business data. Data access objects (DAO) objects may be part of a Model, but they are not the only objects that make up a business object Model.
    • If this web framework example has business logic coded in whatever the Controller is, then it is not accurate.
    • The purpose of the Data Access Object design pattern is to shield the Model from "data" access logic, e.g. physical implementation of a data storage system. Business logic should be loosely coupled with infrastructure logic and data (CRUD) logic. Design patterns such as Data Access Object and Service Locator provide a guide on how to realize this.

In MVC , DAO should be called from Controller or Model

  • In my opinion, you have to distinguish between the MVC pattern and the 3-tier architecture. To sum up:
    • 3-tier architecture:
      • data: persisted data;
      • service: logical part of the application;
      • presentation: hmi, webservice...
    • The MVC pattern takes place in the presentation tier of the above architecture (for a webapp):
      • data: ...;
      • service: ...;
      • presentation:
        • controller: intercepts the HTTP request and returns the HTTP response;
        • model: stores data to be displayed/treated;
        • view: organises output/display.
    • Life cycle of a typical HTTP request:
      1. The user sends the HTTP request;
      2. The controller intercepts it;
      3. The controller calls the appropriate service;
      4. The service calls the appropriate dao, which returns some persisted data (for example);
      5. The service treats the data, and returns data to the controller;
      6. The controller stores the data in the appropriate model and calls the appropriate view;
      7. The view get instantiated with the model's data, and get returned as the HTTP response.