MiniDraw Introducing a Framework... and a few patterns.

Slides:



Advertisements
Similar presentations
Software Engineering 2003 Jyrki Nummenmaa 1 OBJECT ARCHITECTURE DESIGN These slides continue with our example application, based on the simplified.
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.
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
Object-Oriented Analysis and Design
Design patterns Observer,Strategi, Composite,Template (Chap 5, 6)
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
More OOP Design Patterns
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Introduction To System Analysis and design
Behavioral Patterns  Behavioral patterns are patterns whose purpose is to facilitate the work of algorithmic calculations and communication between classes.
Microsoft Visual Basic 2005: Reloaded Second Edition
Faculty of Informatics and Information Technologies Slovak University of Technology Peter Kajsa and Ľubomír Majtás Design.
MVC and MVP. References enter.html enter.html
Model View Controller (MVC) Rick Mercer with a wide variety of others 1.
Case Studies on Design Patterns Design Refinements Examples.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
ISP666 MVC & Design Patterns. Outline Review Event Programming Model Model-View-Controller Revisit Simple Calculator Break Design Patterns Exercise.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
1 Kyung Hee University Diagram Editor : Implementation View Spring 2001.
(c) University of Washington08-1 CSC 143 Models and Views Reading: Ch. 18.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
3461 Model-View Controller Advanced GUI concepts.
Model View Controller (MVC) Bigger than a Pattern: It’s an Architecture Rick Mercer with help from many others 1.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Frameworks CompSci 230 S Software Construction.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 13. Review Shared Data Software Architectures – Black board Style architecture.
Behavioural Design Patterns Quote du jour: ECE450S – Software Engineering II I have not failed. I've just found 10,000 ways that won't work. - Thomas Edison.
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)
CS 151: Object-Oriented Design October 15 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
The HotCiv GUI Instantiating the MiniDraw Framework.
Test Stubs... getting the world under control. TDD of State Pattern To implement GammaTown requirements I CS, AUHenrik Bærbak Christensen2.
Behavioral Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 31. Review Creational Design Patterns – Singleton Pattern – Builder Pattern.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMMING PRACTICES Model View.
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.
The Facade Pattern (Structural) ©SoftMoore ConsultingSlide 1.
Deriving State…...and an example of combining behaviour.
L10: Model-View-Controller General application structure. User Interface: Role, Requirements, Problems Design patterns: Model – View – Controller, Observer/Observable.
Multi Dimensional Variance: How to make ultra flexible software!
Applying the Principles Two Examples. Example 1 New Requirement It would be nice with a simple GUI “to see something” instead of just xUnit tests...
CS, AUHenrik Bærbak Christensen1 Compositional Design Principles The “GoF” principles Or Principles of Flexible Design.
Mandatory 3 Test Stubs State Abstract Factory. Stubs, Spies, and Fake Objects One Example Making distribution testable... Henrik Bærbak Christensen2.
Mandatory 3 Test Stubs State Abstract Factory. Do not panic! dSoftArk is about Good analyzable design not about HotCiv! Henrik Bærbak Christensen2.
Strategy in 15 minutes... derived from the principles.
CSHenrik Bærbak Christensen1 Flexibility and Maintainability And their metrics: coupling and cohesion.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Instantiating the MiniDraw Framework
Introducing a Framework ... and a few patterns
Design Patterns: MORE Examples
Software Design Refinement Using Design Patterns
Applying the Principles
Behavioral Design Patterns
Observer Design Pattern
Compositional Design Principles
Presented by Igor Ivković
CS102 – Bilkent University
Model-View-Controller (MVC) Pattern
Patterns.
Chapter 20 Object-Oriented Analysis and Design
Advanced ProgramMING Practices
Advanced ProgramMING Practices
Model, View, Controller design pattern
Presented by Igor Ivković
Software Engineering and Architecture
Presentation transcript:

MiniDraw Introducing a Framework... and a few patterns

DAIMIHenrik Bærbak Christensen2 What is it? [Demo]

DAIMIHenrik Bærbak Christensen3 What do I get? MiniDraw helps you building apps that have –2D image based graphics GIF files Optimized repainting –Direct manipulation Manipulate objects directly using the mouse –Semantic constraints Keep objects semantically linked

DAIMIHenrik Bærbak Christensen4 History MiniDraw is downsized from JHotDraw JHotDraw –Thomas Eggenschwiler and Erich Gamma –Java version of HotDraw HotDraw –Kent Beck and Ward Cunningham. –Part of a smalltalk research project that lead to the ideas we now call design patterns and frameworks

DAIMIHenrik Bærbak Christensen5 MiniDraw –supporting board games mainly –cut down detail for teaching purposes –one day convert to C# (hmm ?) –MiniDraw: compositional design (most of the time) –JHotDraw: polymorphic design (quite a lot of the time) Newest addition –BoardGame extension: More direct support for board games with fixed set of checkers

Our first MiniDraw application

DAIMIHenrik Bærbak Christensen7 ½ DrawingEditor –“Project manager”/Redaktør –Default implementation Figure –Visible element –ImageFigure Drawing –container of figures Tool –= controller Factory –create impl. of MiniDraw roles DrawingView –view type to use...

The Patterns in MiniDraw Not what but why? The principles in action again...

DAIMIHenrik Bærbak Christensen9 MiniDraw software architecture Main JHotDraw architecture remains –Model-View-Controller architectural pattern Drawing-DrawingView-Tool –Observer pattern event mechanism

DAIMIHenrik Bærbak Christensen10 MVC’ problem statement Challenge: –writing programs with a graphical user interface –multiple open windows showing the same data – keeping them consistent –manipulating data in many different ways by direct manipulation (eg. move, resize, delete, create,...) i.e. switching tool will switch the object manipulation

DAIMIHenrik Bærbak Christensen11 Challenge 1 Keeping multiple windows consistent? Analysis: –Data is shared but visualization is variable! –  Data visualisation is variable behaviour –  Responsibility to visualize data is expressed in interface: View –  Instead of data object (model) itself is responsible for drawing graphics it lets someone else do the job: the views > View update() Model * View A View B

DAIMIHenrik Bærbak Christensen12 Challenge 2 Few mouse events (down, up, drag) translate to open-ended number of actions (move, resize, create, ?) on data. –Events are the same but manipulation is variable –  Data manipulation is variable behaviour –  Responsibility to manipulate data is expressed in interface: Controller –  Instead of graphical view itself is responsible for manipulating data it lets someone else do the job: the controller > Controller mouseDrag() View Select Move Model

DAIMIHenrik Bærbak Christensen13 Observer Challenge 1: –Also known as observer pattern Intent –Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.

Observer: Structure DAIMIHenrik Bærbak Christensen14

Observer Protocol Protocol: A convention detailing the expected sequence of interactions or actions expected by a set of roles. DAIMIHenrik Bærbak Christensen15

DAIMIHenrik Bærbak Christensen16 Observer Benefits open ended number of viewer types (run-time binding) need not be known at develop time –change by addition, not by modification... any number of views open at the same time when executing all guarantied to be synchronized Liabilities update sequence can become cyclic or costly to maintain

DAIMIHenrik Bærbak Christensen17 State Challenge 2: –Also known as state pattern Intent –Allow an object to alter its behaviour when its internal state changes. The object will appear to change its class. –i.e. when the editor is in “draw rectangle” state, the mouse events (click, drag, release) will create a rectangle; when in “select object” state, the same (click, drag, release) will move an object…

DAIMIHenrik Bærbak Christensen18 State Consequences the manipulation that is active determine the application state (“am I moving or resizing figures?”) open ended number of manipulations (run-time binding) need not know all states at compile time –change by addition...

Selected Tool defines the State In MiniDraw (HotDraw) the editor is in a state that determines how mouse events are interpreted – do they move a checker, do they select a set of figures, or do they create a rectangle? Mouse events are forwarded to the editor’s tool. By changing the tool I change how mouse events are interpreted. DAIMIHenrik Bærbak Christensen19

MVC The MVC is an architectural pattern because it defines a solution to the problem of structuring the ’large-scale’ / architectural challenge of building graphical user interface applications. But the ’engine behind the scene’ is a careful combination of state and observer... That again are example of using the variability handling process. DAIMIHenrik Bærbak Christensen20

DAIMIHenrik Bærbak Christensen21 Static view

DAIMIHenrik Bærbak Christensen22 Responsibilities

Dynamics

MiniDraw

DAIMIHenrik Bærbak Christensen25 MiniDraw: Static+Pattern View

Tool: The Controller role

DAIMIHenrik Bærbak Christensen27 MiniDraw: Tool Interaction Basic paradigm: Direct Manipulation [Demo: puzzle]

DAIMIHenrik Bærbak Christensen28 View -> Controller interaction Mouse events do hit the JPanel, but MiniDraw simply delegate to its active tool...

DAIMIHenrik Bærbak Christensen29 Example Tool Scenario: User drags image figure around. Then a DragTracker is the active tool:

The real story … is somewhat more complex as it involves a bit more delegation StandardDrawingView is-a JPanel. –This view requests access to the editor’s current tool Aka: delegating the request to state.request() DAIMIHenrik Bærbak Christensen30

DAIMIHenrik Bærbak Christensen31 Tools MiniDraw has some simple tools defined

DAIMIHenrik Bærbak Christensen32 Code view It is very simple to set a new tool: editor.setTool( t ); where t is the tool you want to become active. NullTool is a Null Object: a tool that does nothing.

Drawing: The Model role

DAIMIHenrik Bærbak Christensen34 MiniDraw: Drawing Static view

DAIMIHenrik Bærbak Christensen35 MiniDraw: Drawing But how does the view get repainted? –Double observer chain Figure notifies drawing notifies drawing view.

DAIMIHenrik Bærbak Christensen36 Exercise: Observer pattern has two roles –Subject: Container of data –Observer: Object to notify upon data changes Who are who here??? DrawingView Drawing Figure

DrawingView: The View role

DAIMIHenrik Bærbak Christensen38 View The View is rather simple –JPanel to couple MiniDraw to concrete Swing GUI implementation –Listen to mouse events to forward them to tool/controller.

The Compositional Advantage Note that this design combines two frameworks –MiniDrawandSwing –If DrawingView was not an interface then 

DrawingEditor: The Coordinator

Static View

Implementation

DAIMIHenrik Bærbak Christensen43 Default Implementations Most MiniDraw roles have default implementations: –Interface X has default implementation StandardX –Drawing -> StandardDrawing There are also some partial implementations: –Interface X has partial implementation AbstractX –Tool -> AbstractTool –Figure -> AbstractFigure

Complex behaviour as a result of combining simple behaviour... Example: –StandardDrawing –Responsibilities DAIMIHenrik Bærbak Christensen44 Compositional Design

DAIMIHenrik Bærbak Christensen45 How do we do that? Proposal 1: –implement ahead... Proposal 2: –encapsulate major responsibilities in separate objects and compose behaviour Refactor - maybe

Code view: delegations! Examples:

DAIMIHenrik Bærbak Christensen47 What do I achieve? Implementing a custom Drawing –In which the figure collection works differently… –but I can reuse the selection and drawing-change handler behaviour directly!

MiniDraw Variability Points

Variability Points Images –By putting GIF images in the right folder and use them through ImageFigures Tools –Implement Tool and invoke editor.setTool(t) Figures –You may make any new type you wish Drawing –Own collection of figures (e.g. observe a game instance) Observer Figure changes –Make semantic constraints Views –Special purpose rendering

DAIMIHenrik Bærbak Christensen50 Summary MiniDraw is –A framework: A skeleton application that can be tailored for a specific purpose –A demonstration: of MVC, Observer, State, Abstract Factory, Null Object, Strategy,... of compositional design: Make complex behaviour by combining simpler behaviours –A basis: for the mandatory project GUI.