1 / 20

MVC on the web 1.1 with figures from Christian Gross’ book, Ajax Patterns and Practices

MVC on the web 1.1 with figures from Christian Gross’ book, Ajax Patterns and Practices. Design Patterns. The hard problem in object-oriented (O-O) programming is deciding what objects to have, and what their responsibilities are

jania
Télécharger la présentation

MVC on the web 1.1 with figures from Christian Gross’ book, Ajax Patterns and Practices

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. MVC on the web1.1with figures from Christian Gross’ book, Ajax Patterns and Practices

  2. Design Patterns • The hard problem in object-oriented (O-O) programming is deciding what objects to have, and what their responsibilities are • Design Patterns describe recommended designs for common problems • Design patterns are a current hot topic in O-O design • The book which started it all is described here: http://en.citizendium.org/wiki/Design_pattern

  3. Christian Gross’ book, Ajax Patterns and Practices

  4. why Model-View-Controller designs? • in 1870, someone wrote a novel • there is a 2002 audio-tape version of it • there is a 1926 hardback edition of it • there is a 2005 paperback edition of it • in 1987, a film was made of it • one novel – but 4 different ways of presenting it

  5. Model-View-Controller pattern goals • there are often many ways to present the same problem • requirements on how a problem is displayed tend to change (i.e., “experimentation” goes on) • the MVC design tries to separate the code that represents the problem from the code that presents the problem to the user • this allows the “presentation” part to be change more easily • this “pattern” arose because management has so often demanded that programmers modify presentation • without the correct design, that’s “hard” • with this pattern, it becomes much “easier”

  6. About the MVC pattern • Model View Controller • separation of concerns • content (data) is the Model • data may be derived from multiple sources • there are potentially multiple ways of presenting the content • each presentation method is one View • the Controller is the code that (possibly based on user parameters) gets data, from (possibly multiple) sources, and aggregates it into an internal representation • a View takes an internal representation of some data and presents it in the currently appropriate way • based on browser type or device type, for example

  7. An example - Google • Three different browser technologies • Graphical User Interface (IE, Firefox, Safari, Opera, etc.) • Text-based browser • Wireless Access Protocol (WAP) browser • on cell phones

  8. GUI browser

  9. Text-based browser

  10. WAP browser (cell phone)

  11. 2 “permutations” of the same data

  12. generic URL’s • This is what most developers do: • GET /bankaccount/login.jsp • GET /bankaccount/login.aspx • GET /bankaccount/login.php • This might (ideally) be better: (platform independent) • GET /bankaccount/login • But, how could we get the generic URL to go to the current implementation?

  13. Resource vs. Representation • Resource: • GET /bankaccount/login • Representation • GET /bankaccount/login.jsp • GET /bankaccount/login.aspx • GET /bankaccount/login.php

  14. which database shall we use? • what if we want to stop using one database and start using another? • do we need to change the website source code (and maybe recompile)? • the recommended way is to decouple details about where the data is from the logic which uses the data • traditionally, by web.config files (Java or .NET) • Ruby does this a little differently • using a web.config is a form of dependency injection

  15. dependency injection • a contract between an object and the environment • The object agrees not to go out searching for the resources it needs, partners it collaborates with, or services it uses. • Instead, the object provides a means for these dependencies to be provided to it. • In turn, the execution environment agrees to provide the object with all of the dependencies it needs, before the object needs them.

  16. Interfaces in OO languages (a form of runtime binding) class Factory { public static Ibase Instantiate() { return new Implementation2(); } } class Client { void UseIt() { Ibase obj = Factory.Instantiate(); obj.DoSomething(); } } interface Ibase { void DoSomething(); } class Implementation1 : IBase { void DoSomething() { // code here } } class Implementation2 : IBase { void DoSomething() { // code here } }

  17. web servers and root URL’s • all web servers implement the separation of resource from representation for the root URL • “default documents” could be one of many, such as: • index.html • index.jsp • index.pgp • default.aspx

  18. for specific web “applications” • you may need to implement a filter to do URL rewriting • resource: • http://harbormist.com/bankaccount/login • a filter would rewrite the URL as one of: • http://harbormist.com/bankaccount/login.jsp • http://harbormist.com/bankaccount/login.aspx • http://harbormist.com/bankaccount/login.php

  19. example code for a web server filter • Ajax Patterns and Practices, chapter 5, p. 128 • shows how to write an application filter in ASP.NET • an equivalent method exists on Apache web servers

  20. The End

More Related