Your SlideShare is downloading. ×
What is MVC?
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

What is MVC?

6,743
views

Published on

A short primer on Model-View-Controller design.

A short primer on Model-View-Controller design.

Published in: Technology

1 Comment
4 Likes
Statistics
Notes
No Downloads
Views
Total Views
6,743
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
202
Comments
1
Likes
4
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. What is MVC? A Primer in 10 Slides Dominique Gerald M Cimafranca [email_address] http://villageidiotsavant.com By
  • 2. Model-View-Controller
    • an architectural pattern in software engineering
    • 3. a way of designing and building applications
    • 4. object-oriented software development
    • 5. separates application logic from presentation
    • 6. loose coupling between components
  • 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. What happens when you...
    • change the database settings?
    • 9. change the database design?
    • 10. change the database?
    • 11. process more variables?
    • 12. change the response?
    • 13. change the look and feel?
  • 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”); }
    • Controller handles application logic
    • 15. A single controller may have multiple methods
    • 16. A controller collects all the actions that takes place
    • 17. Several controllers may comprise an application
  • 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”); }
    • Controller invokes models
    • 19. Controller manipulates model attributes
    • 20. Controller uses model methods
    • 21. Models can invoke other models
    Customer http://myapp/customer/create http://myapp/customer/read http://myapp/customer/update http://myapp/customer/delete name category quantity : read() save() :
  • 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
    • Controller combines data with template
    • 23. Template may perform additional processing
    • 24. Return combination as HTML
    $header $sidebar for($item in $data) { echo $item; } Our Customers : : : : Charlie Brown Lucy Van Pelt Linus Van Pelt
  • 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
    • Client does not need to be a web browser
    • 26. Can be any client that speaks XML
    • 27. Serialization: conversion of data into bits
    • 28. With this, we can talk about web services
    XML, JSON, YAML, ...
  • 29. Some MVC web frameworks
    • Ruby on Rails (www.rubyonrails.org)
    • 30. CakePHP (www.cakephp.org)
    • 31. CodeIgniter (www.codeigniter.org)
    • 32. Yii (www.yiiframework.com)
    • 33. Django (www.djangoproject.org)
    • 34. CherryPy (www.cherrypy.org)
    • 35. Spring MVC (www.springsource.org)
    • 36. Catalyst (www.catalyst.org)
    • 37. Mojolicious (www.mojolicio.us)
    Frameworks make things easier BUT you don't need to use them to practice MVC
  • 38. License
    • You are free:
      • to Share: to copy, distribute and transmit the work
      • 39. to Remix: to adapt the work
    • Under the following conditions:
      • 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. 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.
    • With the understanding that:
      • Waiver: Any of the above conditions can be waived if you get permission from the copyright holder.
      • 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.
    • Other Rights: In no way are any of the following rights affected by the license:
      • Your fair dealing or fair use rights, or other applicable copyright exceptions and limitations;
      • 42. The author's moral rights;
      • 43. Rights other persons may have either in the work itself or in how the work is used, such as publicity or privacy rights.
    • 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 .