MVC overview Model, View, Controller is MVC

Slides:



Advertisements
Similar presentations
CS0004: Introduction to Programming Visual Studio 2010 and Controls.
Advertisements

OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
Automating Tasks With Macros
Automating Tasks With Macros. 2 Design a switchboard and dialog box for a graphical user interface Database developers interact directly with Access.
Command Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
Object-Oriented Analysis and Design
1 Chapter 5: Introduction To Form Builder. 2 Forms  Why Do We Use Form Builder?  Why Don’t We Use SQL Only?!
Design Patterns academy.zariba.com 1. Lecture Content 1.What are Design Patterns? 2.Creational 3.Structural 4.Behavioral 5.Architectural 6.Design Patterns.
GUI Tutorial Images. Useful Info – not on final exam.
Object-Oriented Design & Patterns Cay S
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
Software Design 4.1 Tell, Don't Ask l Tell objects what you want them to do, do not ask questions about state, make a decision, then tell them what to.
(c) University of Washington08-1 CSC 143 Models and Views Reading: Ch. 18.
Computer Science 111 Fundamentals of Programming I Model/View/Controller and Data model design.
Software Design 9.1 From Using to Programming GUIs l Extend model of "keep it simple" in code to GUI  Bells and whistles ok, should be easy to use and.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
Software Design 8.1 Model, View, Controller: battleship l Who does what, where are responsibilities in MVC?  This is a pattern, so there's isn't "one.
3461 Model-View Controller Advanced GUI concepts.
Term 2, 2011 Week 1. CONTENTS Problem-solving methodology Programming and scripting languages – Programming languages Programming languages – Scripting.
CS130 Project 1 A simple VB application ("project" or program): user enters amount of sales then clicks the "Calculate button", the application displays.
Cairngorm Microarchitecture. Pronunciation Cairngorm (kârn gôrm) n. yellowish-brown variety of quartz, especially found in Scottish Cairngorm mountain.
CPS 108/ola.1 From XP to javax.swing.* l What parts of embracing change can we embrace in 108?  Evolutionary design, small releases, iterative enhancement.
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.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
Object Oriented Programming.  Interface  Event Handling.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 10 1 Microsoft Office Access 2003 Tutorial 10 – Automating Tasks With Macros.
CPS 100 spreadsheet.1 Spreadsheet: Graphs and MVC l Model, View, Controller is MVC  Model stores and updates state of application Example: calculator,
ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are.
Review_6 AWT, Swing, ActionListener, and Graphics.
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.
Project JETT/Duke 1 javax.swing, events, and GUIs l GUI programming requires processing events  There’s no visible loop in the program  Wire up/connect.
L10: Model-View-Controller General application structure. User Interface: Role, Requirements, Problems Design patterns: Model – View – Controller, Observer/Observable.
Java - hello world example public class HelloWorld { public static void main (String args[]) { System.out.println("Hello World"); }
1 Chapter 6: Creating Oracle Data Block Forms. 2 Forms  Application with a graphical user interface that looks like a paper form  Used to insert, update,
Engineered for Tomorrow Unit:8-Idioms Engineered for Tomorrow sharmila V Dept of CSE.
Dive Into® Visual Basic 2010 Express
Microsoft Foundation Classes MFC
Running a Forms Developer Application
Programming & Scratch.
A First Look at GUI Applications
Observer Design Pattern
Graphical User Interface (pronounced "gooey")
Lecture 27 Creating Custom GUIs
MVC and other n-tier Architectures
Singleton Pattern Command Pattern
Program and Graphical User Interface Design
Understanding an App’s Architecture
Note 11 Command Pattern SE2811 Software Component Design
Ellen Walker Hiram College
Model-View-Controller Design Pattern
Program and Graphical User Interface Design
Salevich Alex & Frenkel Eduard Wizard Hunting
Event Driven Programming
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
12. Command Pattern SE2811 Software Component Design
Figure 30.2 Layers in NextGen
Model-View-Controller Patterns and Frameworks
Interactive Input Methods & Graphical User Input
Web Application Architectures
Model-View-Controller
Game Loop Update & Draw.
Web Application Architectures
Interactive Input Methods & Graphical User Input

12. Command Pattern SE2811 Software Component Design
Model, View, Controller design pattern
Creating a Simple Game in Scratch
Web Application Architectures
CHAPTER FOUR VARIABLES AND CONSTANTS
Presentation transcript:

MVC overview Model, View, Controller is MVC Model stores and updates state of application Example: calculator, what's the state of a GUI-calculator? When model changes it notifies its views Example: pressing a button on calculator, what happens? The controller interprets commands, forwards them appropriately to model (usually not to view) Example: code for calculator that reacts to button presses Controller isn't always a separate class, often part of GUI-based view in M/VC MVC is a fundamental design pattern: solution to a problem at a general level, not specific code per se

MVC in in the jpuzzle suite Sliding puzzle game allows users to move pieces near a blank piece to recreate an original image See PuzzleGui, PuzzleController, PuzzleView, PuzzleModel, PuzzleApplet, PuzzleMove The model “knows” the location of the pieces Determines if move is legal Makes a move (records it) and updates views Supports move undo View shows a board and information, e.g., undo possible See PuzzleView interface, implemented by application and applet

Puzzle MVC: Controller perspective In this example, the PuzzleController is a middleman, all communication between views and model via controller Sometimes a middleman class isn’t a good idea, extra layer of code that might not be needed Often in MVC model communicates with multiple views, but communication to model via controller In this example one controller holds all the views and executes commands in all views on behalf of model Model only calls showBoard in controller Some of the “intelligence” is in controller, arguably should be in model Controller is a candidate for refactoring

Controller and Commands Use-case for making a move: Move generated, e.g., by button-click Move forwarded to model (by controller) If move is made, then undo state set to true in views If move is made, then views update board display Use-case for undoing a move Undo generated, e.g., by button or menu choice Undo forwarded to model (by controller) If undo changes board, views will be updated If future undo not possible, undo state set to false ShowBoard and Undo are both Command classes Command implemented using hook/template method

Hook method and Template Pattern Client code (Controller) calls a command’s execute method, all Commands have such a method Execute always has a view parameter Execute has optional other parameter for information The execute method is the same in every Command, forwards to the hook method Subclasses of ViewCommand implement hook in application specific way Showing board calls appropriate method in view Undo calls appropriate method in view

Lower level JButton particulars PuzzleGui class has panel/grid of buttons for display Pressing button causes action (via controller) Button is displayable, but doesn’t have label If button had label, it would be automatically shown Instead, use setActionCommand to store command Retrieved by getActionCommand, but not a label Button has icon, automatically displayed The Icon interface (swing) implemented by ImageIcon See PlainPuzzleIcon and ImagePuzzleIcon An Icon doesn’t typically grow, but in this application we want it to resize when app is resized

Image drawing and construction In this application, getIconHeight and getIconWidth are implemented by Icon subclasses, but ignored Not used by puzzle button, drawing resizes as needed The paintIcon method passed a Component, information from component used to draw icon appropriately-sized See parameters to drawImage and to fill3DRect passed to graphics object in drawing routines Each ImageIcon knows what piece of image it is and draws this scaled piece with complex drawImage method Determining which piece tricky, need static count (1st piece, 2nd piece, …) on a per-image basis See IconCounterCounter class and use

What about a “real game” How to make this a game? What are use cases/scenarios? Shuffle pieces initially, pick random piece near blank and move it, repeat 5, 10, 20 times [degree of difficulty] How does this facilitate auto-solve? What about showing the numbered tiles as a hint when just image puzzle used by client Auto-complete, we can undo string of moves, track all Coalesce moves that are redundant Recognize previous state of board and go back