Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
What is MVC? A Primer in 10 Slides Dominique Gerald M Cimafranca [email_address] http://villageidiotsavant.com By
Model-View-Controller <ul><li>an  architectural pattern  in software engineering
a way of  designing  and  building  applications
object-oriented  software development
separates   application logic  from  presentation
loose coupling  between components </li></ul>
Without MVC Client database db=connect(database); var1=$_POST[“data1”]; var2=$_POST[“data2”]; db.query(“insert into db val...
What happens when you... <ul><li>change the database settings?
change the database design?
change the database?
Upcoming SlideShare
Loading in …5
×

What is MVC?

8,863 views

Published on

A short primer on Model-View-Controller design.

Published in: Technology

What is MVC?

  1. 1. What is MVC? A Primer in 10 Slides Dominique Gerald M Cimafranca [email_address] http://villageidiotsavant.com By
  2. 2. Model-View-Controller <ul><li>an architectural pattern in software engineering
  3. 3. a way of designing and building applications
  4. 4. object-oriented software development
  5. 5. separates application logic from presentation
  6. 6. loose coupling between components </li></ul>
  7. 7. Without MVC Client database db=connect(database); var1=$_POST[“data1”]; var2=$_POST[“data2”]; db.query(“insert into db values var1,var2”); print “<HTML><H1>Success</H1></HTML>”; http://myapp/create.php http://myapp/read.php http://myapp/update.php http://myapp/delete.php database application presentation All in one program! delete.php update.php read.php create.php
  8. 8. What happens when you... <ul><li>change the database settings?
  9. 9. change the database design?
  10. 10. change the database?
  11. 11. process more variables?
  12. 12. change the response?
  13. 13. change the look and feel? </li></ul>
  14. 14. How does MVC work? Client http://myapp/customer/create http://myapp/customer/read http://myapp/customer/update http://myapp/customer/delete customer (controller) function create() { : : } function read() { : : } function update() { : : } function delete() { : : } function read($id) { Customer->get($id); $data=Customer->read(); : : render($data,”template.tpl”); } <ul><li>Controller handles application logic
  15. 15. A single controller may have multiple methods
  16. 16. A controller collects all the actions that takes place
  17. 17. Several controllers may comprise an application </li></ul>
  18. 18. How does MVC work? Client customer (controller) function create() { : : } function read() { : : } function update() { : : } function delete() { : : } function read($id) { Customer->get($id); $data=Customer->read(); : : render($data,”template.tpl”); } <ul><li>Controller invokes models
  19. 19. Controller manipulates model attributes
  20. 20. Controller uses model methods
  21. 21. Models can invoke other models </li></ul>Customer http://myapp/customer/create http://myapp/customer/read http://myapp/customer/update http://myapp/customer/delete name category quantity : read() save() :
  22. 22. How does MVC work? Client customer (controller) function create() { : : } function read() { : : } function update() { : : } function delete() { : : } function read($id) { Customer->get($id); $data=Customer->read(); : : render($data,”template.tpl”); } name category quantity : read() save() : Customer http://myapp/customer/create http://myapp/customer/read http://myapp/customer/update http://myapp/customer/delete <ul><li>Controller combines data with template
  23. 23. Template may perform additional processing
  24. 24. Return combination as HTML </li></ul>$header $sidebar for($item in $data) { echo $item; } Our Customers : : : : Charlie Brown Lucy Van Pelt Linus Van Pelt
  25. 25. Or we could do it with XML Client customer (controller) function create() { : : } function read() { : : } function update() { : : } function delete() { : : } function read($id) { Customer->get($id); $data=Customer->read(); : : render($data,”template.tpl”); } name category quantity : read() save() : Customer XML request XML response $xml->serialize($data) Whatever... Java C / C++ JavaScript <ul><li>Client does not need to be a web browser
  26. 26. Can be any client that speaks XML
  27. 27. Serialization: conversion of data into bits
  28. 28. With this, we can talk about web services </li></ul>XML, JSON, YAML, ...
  29. 29. Some MVC web frameworks <ul><li>Ruby on Rails (www.rubyonrails.org)
  30. 30. CakePHP (www.cakephp.org)
  31. 31. CodeIgniter (www.codeigniter.org)
  32. 32. Yii (www.yiiframework.com)
  33. 33. Django (www.djangoproject.org)
  34. 34. CherryPy (www.cherrypy.org)
  35. 35. Spring MVC (www.springsource.org)
  36. 36. Catalyst (www.catalyst.org)
  37. 37. Mojolicious (www.mojolicio.us) </li></ul>Frameworks make things easier BUT you don't need to use them to practice MVC
  38. 38. License <ul><li>You are free: </li><ul><li>to Share: to copy, distribute and transmit the work
  39. 39. to Remix: to adapt the work </li></ul><li>Under the following conditions: </li><ul><li>Attribution: You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
  40. 40. Share Alike: If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one. </li></ul><li>With the understanding that: </li><ul><li>Waiver: Any of the above conditions can be waived if you get permission from the copyright holder.
  41. 41. Public Domain: Where the work or any of its elements is in the public domain under applicable law, that status is in no way affected by the license. </li></ul><li>Other Rights: In no way are any of the following rights affected by the license: </li><ul><li>Your fair dealing or fair use rights, or other applicable copyright exceptions and limitations;
  42. 42. The author's moral rights;
  43. 43. Rights other persons may have either in the work itself or in how the work is used, such as publicity or privacy rights. </li></ul><li>Notice: For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page . </li></ul>

×