Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo

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?

More Related Content

What is MVC?

  • 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
  • 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?
  • 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
  • 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
  • 28. With this, we can talk about web services XML, JSON, YAML, ...
  • 29. Some MVC web frameworks Ruby on Rails (www.rubyonrails.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;
  • 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 .