# Design Patterns

# Model View Controller

Traditionally used for desktop graphical user interfaces (GUIs), this pattern has become popular for designing web applications.

image-20201228232532359

image-20201228232616883

# Controller

  • Handles clients request
  • Not much code
  • Asks model for information
  • Handles failure and success

# Model

  • Handles data logic
  • Interacts with database

# View

  • Handles data presentation
  • Dynamically rendered
  • Only cares about presentation

Model and view never interact with each other

Model handles all the data

View handles all the presentation

Controller just tells what to do

# Example) blog post

  1. Web browser or client sends the request to the web server, asking the server to display a blog post.
  2. The request received by the server is passed to the controller of the application.
  3. The controller asks the model to fetch the blog post.
  4. The model sends the blog post to the controller.
  5. The controller then passes the blog post data to the view.
  6. The view uses blog post data to create an HTML page.
  7. At last, the controller returns the HTML content to the client.

# Model View View-Model

image-20201229003727250

image-20201229003920224

image-20201229004117106

  1. Easily understandable
  2. Easily extendable
  3. Easily testable

# Model

  • Database

# ViewModel

  • Business logic
  • Functions.

# View

  • UI
  • View should not have business logic

# Data binding

  • View references view-model and checks for change to update itself.
Last Updated: 3/1/2021, 9:19:08 PM