1 / 22

Model-View-Controller

Model-View-Controller. CS 4720 – Web & Mobile Systems. Abstractions and Tiers. Every system we seem to build we talk about tiers How do we reason about the architecture of a system? How can we communicate how the pieces fit together?. A Two-Tier System. A Two-Tier System?.

cuyler
Download Presentation

Model-View-Controller

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Model-View-Controller CS 4720 – Web & Mobile Systems

  2. Abstractions and Tiers • Every system we seem to build we talk about tiers • How do we reason about the architecture of a system? • How can we communicate how the pieces fit together? 2

  3. A Two-Tier System 3

  4. A Two-Tier System? 4

  5. Describing the World • We generally refer to client/server systems as “two-tier systems” • Why? • What does that communicate? 5

  6. A Three-Tier System • How might a three-tier system be different than a two tier? • Do we add a server? • Do we add a client? • What does it mean to havethree tiers? 6

  7. Context Clues • It’s all in what you’re talking about. • If you’re discussion theoverall system, includingthe client, a common view of a three-tier architecture might be this: 7

  8. Context Switch • What if we are talking about just inside our application? • We assume that the client is there, but it is somewhat immaterial • How do we define the layers now? 8

  9. Three-Tier Architecture 9

  10. Three-Tier Architecture • We will see this architecture pattern over and over again in this class • Web development • Web services • Android (basically all mobile…) • Here we are discussing it in the context of a RESTful web architecture 10

  11. Principles of REST • Remember this one? • 3. Addressable Resources • Everything has its place and every place has a thing • “Everything is a resource” • This is actually key to how we go about building a three-tier web application 11

  12. RESTful Tiers • If every resource is a place, and every place is a resource, how do we define our resources? • We know the URL would look something like: • http://mysite.com/users/mss2x • Where: • mysite.com is the domain • users is the “category of resources” • mss2x is a specific instance of the resource 12

  13. RESTful Tiers • What we want the web server / web application to do is translate this: • http://mysite.com/users/mss2x • Into effectively a function call that • Identifies what the user is asking for • Loads a particular resource • Displays the pertinent info about that resource back to the user 13

  14. Model-View-Controller • This is the definition of what MVC is • The MVC pattern maps: • Identifies what the user is asking for • Loads a particular resource • Displays the pertinent info about that resource back to the user • To Model, Controller, View (in that order) 14

  15. MVC 15

  16. MVC 16

  17. Controller • The role of the controller is basically traffic cop • It takes the request from the user and (with the assistance of the server and routing rules) turns it into a method call of sorts • It finds the appropriate model to load • It finds the appropriate view to load • It returns the whole thing back to the user 17

  18. Model • The model is the representation of the data • This may or may not be directly linked to a database (but often is in larger apps) • A model is often translated directly into a DB table, with the columns as its attributes • Think “class definition w/ DB backend” • Often contains relationship rules (a Student has many Classes, for instance) 18

  19. View • The closest thing to what you’ve been dealing with so far is the view • It’s effectively an HTML template that will be populated with the appropriate data from the loaded model • It often has PHP (or whatever) embedded in it • All UI components go here 19

  20. Putting it all Together • So, if you were building a blog, what might some of the models be? • What are the resources that should have addresses to them? • How do they relate to each other? 20

  21. REST and MVC • REST and MVC aren’t directly related, but they intersect in many, many ways • The idea of “nouns” in the system – of addressable resources – is a major component of both • In general, a good MVC system will be RESTful, although a RESTful system does not have to follow MVC. 21

  22. Example Code • What do some of these things look like? 22

More Related