L10: Model-View-Controller General application structure. User Interface: Role, Requirements, Problems Design patterns: Model – View – Controller, Observer/Observable.

Slides:



Advertisements
Similar presentations
Framework is l Reusable Code, often domain specific (GUI, Net, Web, etc) l expressed as l a set of classes and l the way objects in those classes collaborate.
Advertisements

Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
MVC Nick Lopez Duplication of course material for any commercial purpose without the explicit written permission of the professor is prohibited.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Reza Gorgan Mohammadi AmirKabir University of Technology, Department of Computer Engineering & Information Technology Advanced design.
Graphical User Interface (GUI) Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Week 8 Implementation Design Alex Baker. Implementation Design System Design – Describes what the system should do Implementation Design – Describes what.
Graphical User Interface (GUI) Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
MVC Fall 2005 OOPD John Anthony. Design Patterns The hard problem in O-O programming is deciding what objects to have, and what their responsibilities.
Object-Oriented Analysis and Design
Design patterns Observer,Strategi, Composite,Template (Chap 5, 6)
More OOP Design Patterns
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
3/15/05H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout)
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 18 Slide 1 Software Reuse 2.
Dependency Injection and Model-View-Controller. Overview Inversion of Control Model-View-Controller.
MVC pattern and implementation in java
Design Patterns.
Software Construction Lecture 10 Frameworks
Java Swing, Events and MVC Optional Readings: Eckel’s Thinking in Java: Chap 14 (
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
(c) University of Washington08-1 CSC 143 Models and Views Reading: Ch. 18.
COMP 6471 Software Design Methodologies Winter 2006 Dr Greg Butler
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Model View Controller (MVC) Bigger than a Pattern: It’s an Architecture Rick Mercer with help from many others 1.
An Introduction to Programming and Object Oriented Design using Java 3 rd Edition. Dec 2007 Jaime Niño Frederick Hosch Chapter 18 Integrating user interface.
Frameworks CompSci 230 S Software Construction.
Title Carolina First Steering Committee October 9, 2010 Online Voting System Design Yinpeng Li and Tian Cao May 3, 2011.
Software Design 5.1 From Using to Programming GUIs l Extend model of "keep it simple" in code to GUI  Bells and whistles ok, but easy to use and hide.
Model View Controller MVC Web Software Architecture.
Design Patterns. OO-Concepts Don’t rewrite code Encapsulation Inheritance Write flexible code.
Model View Controller (MVC) Bigger than a Pattern: It’s an Architecture Rick Mercer with help from many of others 1.
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
CSE 332: Design Patterns Review: Design Pattern Structure A design pattern has a name –So when someone says “Adapter” you know what they mean –So you can.
Design Reuse Earlier we have covered the re-usable Architectural Styles as design patterns for High-Level Design. At mid-level and low-level, design patterns.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 6: Using Design Patterns.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMMING PRACTICES Model View.
Object Arts.com “Twisting the Triad” The evolution of the Dolphin Smalltalk MVP framework Andy Bower Blair McGlashan Object Arts Ltd.
1 CSE 331 Model/View Separation and Observer Pattern slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia.
Java Swing, Events Readings: Just Java 2: Chap 19 & 21, or Eckel’s Thinking in Java: Chap 14 Slide credits to CMPUT 301, Department of Computing Science.
1 SERVICE ORIENTED ARCHITECTURE ANTHONY GACHANGO D61/70547/2008 DIS 601.
MiniDraw Introducing a Framework... and a few patterns.
Observer / Observable COMP 401 Fall 2014 Lecture 14 10/7/2014.
3/1/01H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout)
High degree of user interaction Interactive Systems: Model View Controller Presentation-abstraction-control.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Presented by Alexey Vedishchev Developing Web-applications with Grails framework American University of Nigeria, 2016 Intro To MVC Architecture.
1 Visual Basic: An Object Oriented Approach 7 – The User interface.
Java SWING and Model View Controller (MVC)
Introduction to Design Patterns
Observer Design Pattern
Activities and Intents
MVC and other n-tier Architectures
What is MVC Category: System MVC=Model-View-Controller
CS102 – Bilkent University
Web Programming Language
Model-View-Controller Patterns and Frameworks
Patterns.
Advanced ProgramMING Practices
Model-view-controller
Advanced ProgramMING Practices
Model, View, Controller design pattern
11. MVC SE2811 Software Component Design
Chapter 8, Design Patterns Introduction
11. MVC SE2811 Software Component Design
Presentation transcript:

L10: Model-View-Controller General application structure. User Interface: Role, Requirements, Problems Design patterns: Model – View – Controller, Observer/Observable. Implementation problems and strategies in Java and C++.

2 Some domain- specific code General Structure An application generally consists of: Some user- interface code Some platform- specific code

3 But What Does It Look Like? No Separation Partitioned Separated

4 Role of the User Interface 1.To represent the domain model to the user 2.To allow the user to control the model.  NOT to be part of the model.

5 User Interface Requirements Represent objects of interest. Provide alternative representations. Allow control via different mechanisms. Implies that the user interface must be loosely-coupled to the application model.

6 Potential Problems 1.How does the controller part of the interface ‘know’ when an interaction is requested? (Event-driven programming)‏ 2.What happens if the model is (sometimes) CPU intensive? (Threads)‏

7 Decoupling A flexible, loosely-coupled arrangement is appropriate for this separation of application model and user interface. The Model-View-Controller design pattern derived from Smalltalk is a useful construct.

8 Design Patterns (1)‏ “Generally, descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context.” -- Design Patterns, p3.

9 Design Patterns (2)‏ The intention is not necessarily to reuse the code that implements a design pattern wholesale, but rather to understand the solution mechanism so well that writing new implementations of the pattern can be done efficiently.

10 Model-View-Controller A design pattern consisting of a triad of classes: –Model - the application object, –View - the screen presentation of the object, –Controller - defines the way the user interface reacts to input. Classes are decoupled by defining a subscribe/ notify protocol. Multiple views and controllers can be defined.

11 Model-View-Controller Relies on an Observer mechanism (another design pattern) to connect the classes. A View must ensure that it accurately and completely reflects the current state of the Model. The Model notifies all Views that depend on it. The Controller modifies the state of the object through its programming interface in response to user actions.

12 Advantages Multiple views can be added to an object. Multiple control mechanisms can be implemented. Presentation and control of the model can be changed without rewriting the model itself.

13 Why Is This Useful? It allows application-specific code to be localized. It allows the view to be different from the model. It allows multiple differing views of the same model. It allows the mechanism for control to be separate from both the view and the model.

14 MVC in Java Java.util.Observable - a base class that incorporates the observer mechanism. Java.util.Observer - an interface that can be implemented which notices when objects that it is observing change state. The Swing user interface classes use the Model-View-Controller pattern as a basis.

15 Implementation in Java Model classes extend Observable. View classes extend Applet and implement Observer. Each View must : –implement the update () method and –be added to the Model instance via addObserver (). When the Model calls notifyObservers (), the update () method of all observing Views will be called.

16 Implementation in C++ No explicit code for Observer/Observable mechanisms. View and Controller interact with the Model via normal ‘Get’ and ‘Set’ functions. Some libraries allow ‘callback’ functions, e.g. OpenGL™ and qt. For an alternative view, see outerface (

17 Model creates View creates Controller Who creates Model? Version 1: App App

18 Version 1: App Model really is model and nothing else. App is responsible for registering any number of observers/controllers. M + V + C components can all be controlled directly from App (good???). Have to create M, then V, then register, then update M. Make model constructor responsible for adding views?

19 creates View creates Controller creates Model Who creates Model? Version 2: Controller App

20 Version 2: Controller Controller automatically gets a reference to the model. Becomes responsible for initiating all state changes to model (including creation). Has to surrender a reference to the model to let the view be added as an observer. Ends up being responsible for adding observers to model (not ideal). Implies only one controller.

21 creates View creates Controller creates Model Who creates Model? Version 3: View App

22 Version 3: View View responsible for adding itself as observer to model. Implies only one view. Multiple views might share reference to model rather than each create one.

23 When View is Controller For example, sliders and text fields. Situation: View has to become Observable as well as Observer. Problem: Multiple inheritance. Possible Solution: Don’t treat view- controllers as views — tie the “view” part of the controller to another part of the controller rather than to the model.

24 Summary Flexible decoupling of user interface and application is essential. Model-View-Controller is a useful design pattern. Java is amenable to MVC implementation through the Observer/Observable classes. Complete decoupling is not always possible, or may lead to inelegant code.