1 / 13

Model-View Controller

Model-View Controller. Design pattern presentation and discussion Rajat arya ( rajata@u ) EFECS * OIM. Agenda. Definition what is this fancy thing called MVC? History / Origins where does it come from? Functional Description how does MVC actually work? Goal / Benefits

ron
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 Design pattern presentation and discussion Rajat arya (rajata@u) EFECS * OIM

  2. Agenda • Definition • what is this fancy thing called MVC? • History / Origins • where does it come from? • Functional Description • how does MVC actually work? • Goal / Benefits • why is it important? • Example Scenarios • where could MVC be used? • Sample MVC Implementation Review • lets see this thing actually working • Modern Implementations • where does it exist right now? • Questions? • Reference Materials

  3. MVC Definition The Model-View Controller Paradigm is a triad of classes used to build modular applications. MVC consists of three components (objects): Model – application object (data) View – user interface (presentation) Controller – defines how user interface reacts to user action

  4. History First Appeared Formally in: “A cookbook for using the model-view controller user interface paradigm in Smalltalk-8” by Glenn E. Krasner and Stephen T. Pope Journal of Object-Oriented Programming, 1(3):26-49 August/September 1988

  5. Functional Description Intro – Observer Pattern MVC utilizes two applications of the Observer Pattern Observer Pattern (aka Publish-Subscribe) Attach / Detach / Notify Decouples Subjects from Observers, subjects do not know about observers directly

  6. MVC Functional Description View Controller Model MVC Definition: Specific application of the Observer Design Pattern Model is application object (data) View is the user interface (presentation) – observes Model Controller defines way user interface reacts to input – observes View Observer Pattern Used Twice (Controller observes View and View observes Model)

  7. MVC Functional Description (2) View (1) Controller (3) (2) Model Controller maintains knowledge of both View and Model, View has knowledge of Model Controllerobserves changes in View (1), informs Model (2) Viewobserves changes in Model (3) and updates

  8. Goal / Benefits • Modularity • decoupling components • allows each component to be versioned independently • worked on by individuals on team (UI person, DB person, etc) • Flexibility • multiple Views for one Model (web frontend, desktop frontend, mobile frontend, etc) • replace one component (replace data storage from flat file to database) • Maintainability • only change one component where bug exists, less risk in late changes • Testability • each component communicates through contract so each component can be unit-tested independently

  9. Example Scenarios • Spreadsheet application (classic) • same data (model) spreadsheet can have multiple charts (views) • updating spreadsheet should result in updated charts • example of multiple views, single controller, single model • Scaling an application • view is desktop or web, model is a flat-file database • updating the database to clustered set of SQL servers • only model needs to take changes for architecture, controller connects to new model and doesn’t know that the model is now backed by several DBs instead of one file • Multiple user interfaces to application • web interface, mobile phone interface, point-of-sale interface, desktop interface • multiple views, multiple controllers, single model

  10. Sample Implementation Review Small WPF Application written in C# to illustrate how MVC. Email me if you would like a copy of the source code.

  11. Modern Implementations • GUI Frameworks for desktop applications • Application Kit – part of Cocoa for OS X desktop apps • GTK+ - part of GTK libraries, used in lots of apps • Microsoft Foundation Classes (MFC) – Document/View Architecture • Java Swing • Windows Presentation Framework (WPF) • TK Toolkit – part of Tcl/Tk • Implementations of MVC in web-based frameworks • ASP .NET MVC Framework (.NET) • ProMesh.NET (.NET) • Grails (Java) • Struts (Java) • Spring (Java) • PureMVC (JavaScript) • Ruby on Rails (Ruby) • Zend Framework (PHP) • Django (Python) • Pylons (Python)

  12. Fin. Questions?

  13. Reference Links • Design Patterns: Elements of Reusable Object-Oriented Software • If you get nothing else from this talk, please go look this up – it is the most important book I’ve read regarding object-oriented programming:http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1233361435&sr=8-1 • MVC • http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller • http://www.ootips.org/mvc-pattern.html • http://c2.com/cgi/wiki?ModelViewController • http://st-www.cs.uiuc.edu/users/smarch/st-docs/mvc.html • Observer Pattern • http://www.research.ibm.com/designpatterns/example.htm • http://en.wikipedia.org/wiki/Observer_pattern • http://msdn.microsoft.com/en-us/library/ms954621.aspx

More Related