Design Pa*erns. + Anima/on Undo/Redo Graphics and Hints

Similar documents
Design Pattern. CMPSC 487 Lecture 10 Topics: Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, et al.)

Software Design COSC 4353/6353 D R. R A J S I N G H

Design pa*erns. Based on slides by Glenn D. Blank

Using Design Patterns in Java Application Development

DESIGN PATTERN - INTERVIEW QUESTIONS

The Strategy Pattern Design Principle: Design Principle: Design Principle:

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Object-Oriented Design

Ingegneria del Software Corso di Laurea in Informatica per il Management. Design Patterns part 1

EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 6: Design Patterns

Design patterns. OOD Lecture 6

Design Patterns. An introduction

What is Design Patterns?

Design Patterns. Manuel Mastrofini. Systems Engineering and Web Services. University of Rome Tor Vergata June 2011

Object Oriented Methods with UML. Introduction to Design Patterns- Lecture 8

SDC Design patterns GoF

Tuesday, October 4. Announcements

Object-oriented Software Design Patterns

DESIGNING, CODING, AND DOCUMENTING

Trusted Components. Reuse, Contracts and Patterns. Prof. Dr. Bertrand Meyer Dr. Karine Arnout

Topics in Object-Oriented Design Patterns

Introduction to Software Engineering: Object Design I Reuse & Patterns

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Design Patterns. Gunnar Gotshalks A4-1

Structure Patters: Bridge and Flyweight. CSCI 3132 Summer

2.1 Design Patterns and Architecture (continued)

2.1 Design Patterns and Architecture (continued)

Idioms and Design Patterns. Martin Skogevall IDE, Mälardalen University

Applying the Observer Design Pattern

Design Pattern and Software Architecture: IV. Design Pattern

Applying Design Patterns to accelerate development of reusable, configurable and portable UVCs. Accellera Systems Initiative 1

1 Software Architecture

What is Design Patterns?

Review Software Engineering October, 7, Adrian Iftene

OODP Session 4. Web Page: Visiting Hours: Tuesday 17:00 to 19:00

Software Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D.

Object Oriented Paradigm

Design Patterns. SE3A04 Tutorial. Jason Jaskolka

TDDB84: Lecture 6. Adapter, Bridge, Observer, Chain of Responsibility, Memento, Command. fredag 4 oktober 13

Designing and Writing a Program. Divide and Conquer! The Design-Code-Debug Cycle. Documentation is Code. Pair Programming 3/8/2012

CS 349 / SE 382 Design Patterns. Professor Michael Terry January 21, 2009

Socket attaches to a Ratchet. 2) Bridge Decouple an abstraction from its implementation so that the two can vary independently.

The GoF Design Patterns Reference

Object-Oriented Design

Ingegneria del Software Corso di Laurea in Informatica per il Management. Design Patterns part 1

Application Architectures, Design Patterns

Design Patterns. Dr. Rania Khairy. Software Engineering and Development Tool

Object-Oriented Oriented Programming

Applying the Decorator Design Pattern

Design Patterns. CSC207 Fall 2017

Slide 1. Design Patterns. Prof. Mirco Tribastone, Ph.D

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Architectural Requirements Phase. See Sommerville Chapters 11, 12, 13, 14, 18.2


be used for more than one use case (for instance, for use cases Create User and Delete User, one can have one UserController, instead of two separate

Design Patterns Reid Holmes

What is Design Patterns?

Design Patterns. CSC207 Winter 2017

Applying Some Gang of Four Design Patterns CSSE 574: Session 5, Part 3

Design Patterns. (and anti-patterns)

Goals of Lecture. Lecture 27: OO Design Patterns. Pattern Resources. Design Patterns. Cover OO Design Patterns. Pattern Languages of Programming

Lecture 17: Patterns Potpourri. Copyright W. Howden 1

Design patterns. Jef De Smedt Beta VZW

CHAPTER 6: CREATIONAL DESIGN PATTERNS

An Introduction to Patterns

Design Patterns. Observations. Electrical Engineering Patterns. Mechanical Engineering Patterns

MVC. Model-View-Controller. Design Patterns. Certain programs reuse the same basic structure or set of ideas

Facade and Adapter. Comp-303 : Programming Techniques Lecture 19. Alexandre Denault Computer Science McGill University Winter 2004

Applying the Factory Method Design Pattern

COSC 3351 Software Design. Design Patterns Behavioral Patterns (I)

Brief Note on Design Pattern

Design Patterns. CSC207 Fall 2017

DESIGN PATTERNS FOR MERE MORTALS

Summary of the course lectures

CS251 Software Engineering Lectures 18: Intro to DP

Design Pa*erns. Philippe Collet. Master 1 IFI Interna3onal h8p://dep3nfo.unice.fr/twiki/bin/view/minfo/soeeng1213. P.

Command. Comp-303 : Programming Techniques Lecture 22. Alexandre Denault Computer Science McGill University Winter 2004

CPSC 310 Software Engineering. Lecture 11. Design Patterns

A few important patterns and their connections

Plan. A few important patterns and their connections. Singleton. Singleton: class diagram. Singleton Factory method Facade

3 Product Management Anti-Patterns by Thomas Schranz

WS01/02 - Design Pattern and Software Architecture

Software Engineering I (02161)

Patterns. Erich Gamma Richard Helm Ralph Johnson John Vlissides

Applying Design Patterns to SCA Implementations

Lectures 24 and 25 Introduction to Architectural Styles and Design Patterns

The Design Patterns Matrix From Analysis to Implementation

administrivia today UML start design patterns Tuesday, September 28, 2010

Design Patterns and Frameworks Command

Object-Oriented Oriented Programming Command Pattern. CSIE Department, NTUT Woei-Kae Chen

6.3 Patterns. Definition: Design Patterns

Foundations of Software Engineering Design Patterns -- Introduction

CSCI Object Oriented Design: Frameworks and Design Patterns George Blankenship. Frameworks and Design George Blankenship 1

Software Engineering Prof. Rushikesh K.Joshi IIT Bombay Lecture-15 Design Patterns

A Rapid Overview of UML

4.1 Introduction Programming preliminaries Constructors Destructors An example... 3

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

A Reconnaissance on Design Patterns

Think of drawing/diagramming editors. ECE450 Software Engineering II. The problem. The Composite pattern

Transcription:

Design Pa*erns + Anima/on Undo/Redo Graphics and Hints

Design Pa*erns Design: the planning that lays the basis for the making of every object or system Pa*ern: a type of theme of recurring events or objects

Design Pa*erns in OOP Recipes for solving standardized problems Abstrac/ons of concrete problems How to make a class that allows only one instance of itself: The Singleton Design Pa*ern Provides a general solu/on that needs to be implemented

Started from Architecture Architectural Pa*erns Lecture rooms Studies Town Squares Restaurants Etc. Adopted in many non- related areas

Design pa*erns describe how objects communicate without becoming entangled in each other s data models and/or methods.

What is a design pa*ern? A general recipe A framework A template Pre- made solu/on

Design Pa*ern Content Intent what is the goal of the pa*ern? Applicability when should it be used? Structure the pa*ern descrip/on Consequences pros and cons of using the pa*ern.

Good List of Pa*erns Crea%onal pa+erns These pa*erns have to do with class instan/a/on. They can be further divided into class crea/on pa*erns and object- crea/onal pa*erns. While class- crea/on pa*erns use inheritance effec/vely in the instan/a/on process, object- crea/on pa*erns use delega/on to get the job done. Abstract Factory groups object factories that have a common theme. Builder constructs complex objects by separa/ng construc/on and representa/on. Factory Method creates objects without specifying the exact class to create. Prototype creates objects by cloning an exis/ng object. Singleton restricts object crea/on for a class to only one instance. Mul/ton restricts object crea/on for a class to only one instance per given key. Structural pa+erns These concern class and object composi/on. They use inheritance to compose interfaces and define ways to compose objects to obtain new func/onality. Adapter allows classes with incompa/ble interfaces to work together by wrapping its own interface around that of an already exis/ng class. Bridge decouples an abstrac/on from its implementa/on so that the two can vary independently. Composite composes zero- or- more similar objects so that they can be manipulated as one object. Decorator dynamically adds/overrides behaviour in an exis/ng method of an object. Facade provides a simplified interface to a large body of code. Flyweight reduces the cost of crea/ng and manipula/ng a large number of similar objects. Proxy provides a placeholder for another object to control access, reduce cost, and reduce complexity. Behavioral pa+erns Most of these design pa*erns are specifically concerned with communica/on between objects. Chain of responsibility delegates commands to a chain of processing objects. Command creates objects which encapsulate ac/ons and parameters. Interpreter implements a specialized language. Iterator accesses the elements of an object sequen/ally without exposing its underlying representa/on. Mediator allows loose coupling between classes by being the only class that has detailed knowledge of their methods. Memento provides the ability to restore an object to its previous state (undo). Observer is a publish/subscribe pa*ern which allows a number of observer objects to see an event. State allows an object to alter its behavior when its internal state changes. Strategy allows one of a family of algorithms to be selected on- the- fly at run/me. Template method defines the skeleton of an algorithm as an abstract class, allowing its subclasses to provide concrete behavior. Visitor separates an algorithm from an object structure by moving the hierarchy of methods into one object. The "Gang of Four": Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides Design Pa6erns: Elements of Reusable Object- Oriented SoAware

Example The Singleton pa*ern Ensures that one and only one instance can be created from a class private sta/c Singleton m_instance; private Singleton() { } // private constructor public sta/c synchronized Singleton getinstance() { if (m_instance == null) // only create new first /me m_instance = new Singleton(); } return m_instance; // return the single instance

Design Pa*erns vs. Libraries Libraries contain concrete classes Implement concrete solu/ons Design Pa*erns are abstract solu/ons Advice on general solu/ons You can t import a design pa*ern

DP Factory Another interes/ng Design Pa*ern What is a factory? Produc/on unit produces instances mul/ple instances of different classes Ask for a type and you get it!

Factory Example A graphic Shape circles, rectangles, stars, etc. All shapes have size, and can be drawn! The Shape interface defines methods Use a ShapeFactory: public Shape getshape(string type, int size) { }

ShapeFactory, Why? One class provides all shapes! Dynamic crea/on! Consistent usage of Shapes Unless explicitly needed, we don t have to know which Shape we have created ajerwards

ImageReading public interface ImageReader { public DecodedImage getdecodedimage(); } public class GifReader implements ImageReader { public DecodedImage getdecodedimage() { //... return decodedimage; } } public class JpegReader implements ImageReader { public DecodedImage getdecodedimage() { //... return decodedimage; } }

ImageReading Factory public class ImageReaderFactory { public sta/c ImageReader getimagereader(inputstream is) { int imagetype = determineimagetype(is); switch(imagetype) { case ImageReaderFactory.GIF: return new GifReader(is); case ImageReaderFactory.JPEG: return new JpegReader(is); // etc. } } }

UNDO The Undo/Redo mechanism should provide: Single Undo Single Redo (of Undone ac/vity) and, if possible: Undo and redo of several consecu/ve ac/on How can this be acheived?

Command Design Pa*ern One way to handle queues of ac/ons! Important DP for the opera/on of UNDO Simple principle

Command A very simple interface! One method execute() public interface Command { public void execute(); }

Command All ac/vi/es are driven by the execute() method Encapsulate all user ac/vi/es in Command objects

Simple example: Macro public class IAm implements Command { public void execute() { System.out.println("I'm the command pa*ern!"); } } // An object that holds commands: public class Macro { private List commands = new ArrayList(); public void add(command c) { commands.add(c); } } public void run() { Iterator it = commands.iterator(); while(it.hasnext()) ((Command) it.next()).execute(); // Cas/ng! }

UNDO? The execute() method describes what happens during an edit ac/vity UNDO means reversing the edi/ng ac/vity In the command interface add: unexecute() reexecute() Describes the backward process public interface Command { public void execute(); public void unexecute(); // undo public void reexecute(); // redo }

UndoManager UndoManager is support for UNDO in Swing edit types - the effect of a user invoked command each edit type must s/ll have a defini/on of the edit and its effects Simplifies the management of the Undo/Redo

Swing Undo UndoableEdit (Interface) AbstractUndoableEdit (Abstract class) CompoundEdit (class for sequences of undoables) UndoableEditListener (Interface) UndoableEditEvent (no/fica/on object) UndoableManager (Queue manager) Like EventManager UndoableEditSupport (Support class)

Undo/Redo- queue UndoManager op1 op2 op3 op4

Undo/Redo- queue UndoManager op1 op2 op3 op4 op1 op2 op3 op4

Undo/Redo- queue UndoManager op1 op2 op3 op4 op1 op2 op3 op4 op1 op2 op5

Undo Good example program in linked page on course homepage (Assignment 2) Add an undo/redo func/on to your Java apps with Swing

Don ts in GUIs We will be able to do almost anything i GUI design But some things maybe we shouldn t (but no rule without excep/on, of course)

Move things for the user You can control the mouse pointer for the user java.awt.robot library java.awt.robot mousemove(int x, int y); Should you? Most of the /me NO! Bad GUI! One possible excep/on: Guiding help systems

The Robot is s/ll Useful! Can make screencaptures! createscreencapture(rectangle screenrect) returns a BufferedImage

Remove Title Bar of Window You can remove the Titlebar of a window Should you? Maybe, e.g. in AboutBoxes But remember to provide the user with control of the window!

Use Anima/ons You can use anima/ons Should you? Yes, some/mes But restric/vely Beware of percep/on exhaus/on

Use Undo You will be able to Undo things Should you? Yes, but only significant changes Don t undo single character inser/on What is significant?

Use graphic effects Swing allows you to use graphic effects E.g. GradientPaint, Transparency Should you? Yes, but always provide an alterna/ve skin that is clear and dis/nct Make it easy to access Make sure to test that the effects work on the plasorm

Be Crea/ve It is (in principle) your imagina/on (and available /me) that sets the limits for what you can do. Should you? Yes, as long as it is good User Interface Design Yes, as long as it is possible to understand Yes, as long as it makes sense for the intended user groups

Prac/ce Anima/on You have a large toolbox with graphics! Prac/ce using it! Should you? Yes, even if it not all will be used in the Calendar, the more you prac/ce, the more you will know about how and when you should use it!