Model View Controller (MVC) an architecture Rick Mercer with help from many of others 1.

Slides:



Advertisements
Similar presentations
3 Copyright © 2005, Oracle. All rights reserved. Designing J2EE Applications.
Advertisements

Apache Struts Technology
OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
Model-View-Controller Architecture Hector Raphael Mojica.
Model-View-Controller ("MVC") This is a architectural design pattern for interactive applications. This design pattern organizes an interactive application.
Graphical User Interface (GUI) Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
System Architecture Lecture 3 CSE 111 Spring /22/20151Copyright William E. Howden.
Graphical User Interface (GUI) Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Software Architecture Patterns (2). what is architecture? (recap) o an overall blueprint/model describing the structures and properties of a "system"
Object-Oriented Analysis and Design
Application Architectures Vijayan Sugumaran Department of DIS Oakland University.
CMPT 370: Information Systems Design Instructor: Curtis Cartmill, Simon Fraser University – Summer 2003 Lecture Topic: Layered Architecture Class Exercise:
Model View Controller (MVC) Architecture. Terminology and History MVC evolved from Smalltalk-80 Has become a key pattern in web based applications – If.
Apache Struts Technology A MVC Framework for Java Web Applications.
UNIT-V The MVC architecture and Struts Framework.
MVC pattern and implementation in java
MVC and MVP. References enter.html enter.html
Model View Controller (MVC) Rick Mercer with a wide variety of others 1.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAM DESIGN WITH C++ Model View.
Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are.
ASP.NET and Model View Control Jesper Tørresø ITNET2 F08.
Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are.
Design Patterns Phil Smith 28 th November Design Patterns There are many ways to produce content via Servlets and JSPs Understanding the good, the.
Model-View-Controller Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University.
JSP Architecture Outline  Model 1 Architecture  Model 2 Architecture.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
MVC CompSci 230 S Software Construction. MVC Architecture  A typical application includes software to  maintain application data,  document text.
Java Swing, Events and MVC Optional Readings: Eckel’s Thinking in Java: Chap 14 (
Case Study + MVC Lec Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
(c) University of Washington08-1 CSC 143 Models and Views Reading: Ch. 18.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Event Driven Programming, The.
DEV-36: Composite MVP – Building Blocks in Presentation Layer
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
Java Web Development with NetBeans IDE -- Kai Qian Chapter 5 JavaServer Faces (JSF) Technology.
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.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications.
CSC 2720 Building Web Applications Frameworks for Building Web Applications.
1 Java Model-View-Controller - see programming.html#concepts.
Model View Controller MVC Web Software Architecture.
Model View Controller (MVC) Bigger than a Pattern: It’s an Architecture Rick Mercer with help from many of others 1.
Review Class Inheritance, Abstract, Interfaces, Polymorphism, GUI (MVC)
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMMING PRACTICES Model View.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
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.
1 Copyright © 2004, Oracle. All rights reserved. Oracle Application Development Framework.
OBJECT-ORIENTED PATTERNS By: Peter Coad Presented by Peixin Chen.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
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.
Java - hello world example public class HelloWorld { public static void main (String args[]) { System.out.println("Hello World"); }
Apache Struts Technology A MVC Framework for Java Web Applications.
CS320 Web and Internet Programming Web Application and MVC Chengyu Sun California State University, Los Angeles.
High degree of user interaction Interactive Systems: Model View Controller Presentation-abstraction-control.
Programming Paradigms, Software Architectural Patterns, and MVC CS 378 – Mobile Computing for iOS Dr. William C. Bulko.
J2EE Platform Overview (Application Architecture)
Social Media And Global Computing Introduction to The MVC Pattern
Review: Java GUI Programming
Observer Design Pattern
MVC and Design Patterns
Design and Maintenance of Web Applications in J2EE
CS102 – Bilkent University
Model-View-Controller Patterns and Frameworks
Event loops 17-Jan-19.
Advanced ProgramMING Practices
Model-view-controller
Advanced ProgramMING Practices
Model, View, Controller design pattern
Presentation transcript:

Model View Controller (MVC) an architecture Rick Mercer with help from many of others 1

Model View Controller (MVC) The intent of MVC is to keep neatly separate objects into one of tree categories –Model The data, the business logic, rules, strategies, and so on –View Displays the model and usually has components that allows user to edit change the model –Controller Allows data to flow between the view and the model The controller mediates between the view and model

Model The Model's responsibilities –Provide access to the state of the system –Provide access to the system's functionality –Can notify the view(s) that its state has changed

View The view's responsibilities –Display the state of the model to the user At some point, the model (a.k.a. the observable) must registers the views (a.k.a. observers) so the model can notify the observers that its state has changed

Controller The controller's responsibilities –Accept user input Button clicks, key presses, mouse movements, slider bar changes –Send messages to the model, which may in turn notify it observers –Send appropriate messages to the view In Java, listeners are controllers

MVC Misunderstood MVC is understood by different people in different ways It is often misunderstood, but most software developers will say it is important; powerful Lets start it right: –MVC is a few patterns put together

Smalltalk-80™ In the MVC paradigm, the user input, the modeling of the external world, and the visual feedback to the user are explicitly separated and handled by three types of objects, each specialized for its task. –The view manages the graphical and/or textual output to the portion of the bitmapped display that is allocated to its application. –The controller interprets the mouse and keyboard inputs from the user, commanding the model and/or the view to change as appropriate. –The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). 7

Smalltalk-80™Smalltalk-80™ continued The formal separation of these three tasks is an important notion that is particularly suited to MVC Smalltalk-80 where the basic behavior can be embodied in abstract objects: View, Controller, Model, and Object MVC discovered by Trygve Reenskaug in

SunSun says Model-View-Controller ("MVC") is the recommended architectural design pattern for interactive applications MVC organizes an interactive application into three separate modules: –one for the application model with its data representation and business logic, –the second for views that provide data presentation and user input, and –the third for a controller to dispatch requests and control flow. 9

SunSun continued Most Web-tier application frameworks use some variation of the MVC design pattern The MVC (architectual) design pattern provides a host of design benefits 10

Java Server Pages Model 2 Architecture to serve dynamic content –Model: Enterprise Beans with data in the DBMS JavaBean: a class that encapsulates objects and can be displayed graphically –Controller: Servlets create beans, decide which JSP to return, do the bulk of the processing –View: The JSPs generated in the presentation layer (the browser) 11

OO-tips writes The MVC paradigm is a way of breaking an application, or even just a piece of an application's interface, into three parts: the model, the view, and the controller. MVC was originally developed to map the traditional input, processing, output roles into the GUI realm: –Input --> Processing --> Output –Controller --> Model --> View 12

Wikipedia writes Model-View-Controller (MVC) is a software architecture that separates an application's data model, user interface, and control logic into three distinct components so that modifications to one component can be made with minimal impact to the others.software architecturedata model user interfacecontrol logic components MVC is often thought of as a software design pattern. However, MVC encompasses more of the architecture of an application than is typical for a design pattern. Hence the term architectural pattern may be useful (Buschmann, et al 1996), or perhaps an aggregate design pattern.software design patternaggregate design pattern 13

MVC Benefits Clarity of design –easier to implement and maintain Modularity –changes to one doesn't affect other modules –can develop in parallel once you have the interfaces Multiple views –games, spreadsheets, powerpoint, Eclipse, UML reverse engineering, …. 14

Summary (MVC) The intent of MVC is to keep neatly separate objects into one of tree categories –Model The data, the business logic, rules, strategies, and so on –View Displays the model and often has components to allow users to change the state of the model –Imagine pressing arrow on a HuntTheWumpus view Demo JeyPressed –Controller Allows data to flow between the view and the model The controller mediates between the view and model 15

Model The Model's responsibilities –Provide access to the state of the model getters, toString, other methods that provide info –Provide access to the system's functionality changeRoom(int), shootArrow(int) –Notify the view(s) that its state has changed // If extending Java’s Obervable class, do NOT forget // to tell yourself your state has changed super.setChanged(); // Otherwise, the next notifyObservers message will not // send update messages to the registered Observers this.notifyObservers(); 16

View The view's responsibilities –Display the state of the model to users, accept input The model (a.k.a. the Observable) must register the views (a.k.a. Observers) so the model can notify the observers that its state has changed –Java’s Observer/Observable support provides public void addObserver(Observer o)Observer // Adds an observer to the set of observers for this // object, provided that it is not the same as some // observer already in the set. 17

Controller The controller's responsibilities –Respond to user input (events) Button click, key press, mouse click, slider bar change –Send messages to the model, which may in turn notify it observers –Send appropriate messages to the view In Java, controllers are implemented as listeners –An ActionListener object and its actionPerformed method is a Controller 18

Swapping Views Relevant to current project, you will be asked need to swap JPanels (the two Java views) –In our Observer_Simple example, this controller removes and adds Jpanels with this code TwoObserversMain.this.remove(currentView); // Set currentView to one of the Observers the extends JPanel currentView = … the one selected … // To access the enclosing class use ClassName.this TwoObserversMain.this.add(currentView); // I needed both of these refreshes, at least in older Java TwoObserversMain.this.validate(); TwoObserversMain.this.repaint(); 16-19

One view of MVC 20

MVC Misunderstood MVC is understood by different people in different ways It is often misunderstood, but most software developers will say it is important; powerful I believe we started it correctly 21

MVC in an Old Project TicTacToe 22 TextFieldView row _ _ O _ X _ column _ _ _ DrawingView MouseListenerActionListener Game

Questions Do controllers have a user interface? Does a view allow user input? Can a view send messages to the model? Can a view send messages to the controller? Can you have more than one view? Can a system have more than one controller? 23