MVC: It's All a Lie

Milko Kosturkov

  • PHP developer for over 12 years
  • fullstack
  • bachelor in Electronics
  • master in IT
  • contractor
  • Ty's Software
  • Bulgaria PHP Conference 2019 Organizer

Fields I've worked in

SMS and Voice services

MMO Games

local positioning systems 

TV productions

Healthcare

e-commerce

websites

SEO

online video

Why this talk?

  • We need to know our past
  • Mitigate confusion
  • Present a new and better concept

Flashback

  • invented in 1979
  • by Trygve Reenskaug
  • while with Xerox
  • NOT FOR THE WEB
  • for GUI applications
  • with Smalltalk - 80
  • for the "Dynabook"

By Trygve Reenskaug - Trygve Reenskaug, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=31168223

MVC was conceived as a general solution to the problem of users controlling a large and complex data set.

 A Thing

According to Trygve Reenskaug

Something that is of interest to the user. It could be concrete, like a house or an integrated

circuit. It could be abstract, like a new idea or opinions about a paper. It could be a whole,

like a computer, or a part, like a circuit element

Model

According to Trygve Reenskaug

Models represent knowledge. A model could be a single object (rather uninteresting), or it

could be some structure of objects.

There should be a one-to-one correspondence between the model and its parts on the one hand, and the represented world as perceived by the owner of the model on the other hand

View

According to Trygve Reenskaug

A view is attached to its model (or model part) and gets the data necessary for the presentation

from the model by asking questions...

A view is a (visual) representation of its model. It would ordinarily highlight certain attributes of the model and suppress others

... the view will therefore have to know the semantics of the attributes of the model it represents.

Controllers

According to Trygve Reenskaug

A controller is the link between a user and the system. It provides the user with input by

arranging for relevant views to present themselves in appropriate places on the screen. It

provides means for user output by presenting the user with menus or other means of giving

commands and data.

A controller should never supplement the views...

Conversely, a view should never know about user input, such as mouse operations and

keystrokes.

MVC

MVC

MVC

vs

Web MVC

MVC vs Web MVC

Application lyfecycle

  • MVC
    • long run duration
    • continuous input (clicks, keyboard strokes)
    • continuous output (multiple view updates)
  • Web MVC
    • short run duration
    • one time input
    • one time output

MVC vs Web MVC

Models

  • MVC
    • hold the state of the app
    • describe the behavior of the app
    • are reflection of reality
  • Web MVC
    • DBAL
    • DB table mappings

MVC vs Web MVC

Views

  • MVC
    • know the models
    • represent the state of their respective models
  • Web MVC
    • know the models*
    • represent the state of their respective models

MVC vs Web MVC

Controllers

  • MVC
    • respond to user input by calling methods on models
    • select and arrange one or more views
  • Web MVC
    • respond to user input
    • contain a good portion of the application's behavior
    • validate input
    • hold dependencies
    • select one view
    • manipulate models (DB)
    • set HTTP headers
    • communicate with external services
    • ......

Why is Web MVC called MVC at all???

JSP Model 1

JSP Model 2

Music Without Borders
  • Understanding JavaServer Pages Model 2 architecture - an article by Govind Seshadri in JavaWorld in 1999
  • Coined the term MVC
  • Used a Vector for a model and put all logic for manipulating the data in it in the Controller

Struts and MVC2

Controller Problems

  • Poor separation of concerns
  • Tied to the environment it runs on
  • Does a lot of things...
  • ... has a lot of dependencies...
  • ... becomes really fat...
  • ... and hard to maintain.
  • And they even set output headers!

Action-Domain-Responder

  • Coined by Paul M. Jones
  • Designed to better fit client-server environments

Action

  • A function or a class implementing the Command pattern
  • Collects data from the request and passes it to Domain
  • Invoke Domain and retains the result
  • Invokes Responder with any data needed (domain data, request data, other)
    • Does not set output headers
    • Does not touch output in any way

Domain

An entry point into whatever does the domain work (Transaction Script, Service Layer, Application Service, etc.).

Responder

Deals with all output:

  • Sets cookies
  • Sets headers
  • Applies compression
  • Chooses presentation format
  • Renders templates

Copy of MVC: It's all a lie

By Milko Kosturkov

Copy of MVC: It's all a lie

  • 263