1 of 21

Slide Notes

DownloadGo Live

Copy of M.V.C.

No Description

PRESENTATION OUTLINE

M.V.C.

Fat models; stupid views
Photo by polandeze

What is M.V.C., anyway?

M.V.C.

  • M.V.C. stands for Model-View-Controller
  • It is the design pattern favored by Rails
  • It favors separation of concerns, making for easy plug-n-play applications

FIRST: the easy stuff

VIEWS

  • Views display your data
  • They don't care about the data's configuratio

This is a very bad view that is just trying to do too much

WELL, WHAT'S WRONG WITH THAT???

VIEWS

  • Hard to read, hard to know the expected outcome
  • Nigh impossible to re-use

HOW DO WE SOLVE IT?

MODELS TO THE RESCUE

MODELS

  • Models should be fat
  • They have intimate knowledge of the data objects
  • They manipulate the data to give us just what we want

These models are nice and thin, which is terrible

HOW DOES THIS WORK TOGETHER?

INTRODUCING: the Controller

CONTROLLERS

  • Controllers are the lean, mean, machines connecting views and models

CONTROLLERS

  • With routing, they make sure the right view gets the right data
  • They do all the heavy lifting re: routing
  • To make their job easier, data should be neatly delivered

TO RECAP

  • Models should be fat
  • Views should be stupid
  • Controllers are too busy to query the database

THE END.