Implementing GUI context-sensitive help... ECE450 Software Engineering II. Implementing GUI context-sensitive help... Context-sensitive help

Similar documents
» Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request!

Tecniche di Progettazione: Design Patterns

Tecniche di Progettazione: Design Patterns

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

Tecniche di Progettazione: Design Patterns

Tecniche di Progettazione: Design Patterns

L25.1 Introduction... 2

State Pattern. CSIE Department, NTUT Woei-Kae Chen. State: Intent. Allow an object to alter its behavior when its internal state changes.

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

2/23/04 Doc 10 State & Chain of Responsibility slide # 1

Chain of Responsibility Pattern*

The Factory Method Pattern

Design of Software Systems (Ontwerp van SoftwareSystemen) Design Patterns Reference. Roel Wuyts

The Chain of Responsibility Pattern

The Chain of Responsibility Pattern. Design Patterns In Java Bob Tarr

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

Object-Oriented Oriented Programming

Chair of Software Engineering. Languages in Depth Series: Java Programming. Prof. Dr. Bertrand Meyer. Exercise Session 9.

Chain of Responsibility

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

SDC Design patterns GoF

Design Patterns Reid Holmes

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

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

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

Object-Oriented Design

Design Patterns Reid Holmes

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

Design Patterns: State, Bridge, Visitor

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

Design Pattern What is a Design Pattern? Design Pattern Elements. Almas Ansari Page 1

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

Object-Oriented Design

Topics in Object-Oriented Design Patterns

Design Patterns. Gunnar Gotshalks A4-1

Composite Pattern. IV.4 Structural Pattern

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

6.3 Patterns. Definition: Design Patterns

Last Lecture. Lecture 26: Design Patterns (part 2) State. Goals of Lecture. Design Patterns

Last Lecture. Lecture 17: Design Patterns (part 2) Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 4448/ Spring Semester, 2005

The Design Patterns Matrix From Analysis to Implementation

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

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

The Object Recursion Pattern

Design Patterns Design patterns advantages:

Chain of Responsibility

The State Pattern. State Design Pattern: Motivation

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

Design Pattern- Creational pattern 2015

(c) Bartosz Walter 1

Keywords: Abstract Factory, Singleton, Factory Method, Prototype, Builder, Composite, Flyweight, Decorator.

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

THOMAS LATOZA SWE 621 FALL 2018 DESIGN PATTERNS

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

CHAIN OF RESPONSIBILITY (DP 223)

CS342: Software Design. November 21, 2017

Design issues: abstraction and patterns Strategy Pattern Singleton Pattern. CSIE Department, NTUT Woei-Kae Chen

Tecniche di Progettazione: Design Patterns

Design Patterns #3. Reid Holmes. Material and some slide content from: - GoF Design Patterns Book - Head First Design Patterns

The State and Strategy Patterns. Design Patterns In Java Bob Tarr

Design Pattern Detection

Design patterns Behavioral Pattern 2015

Design Patterns Revisited

RDD and Strategy Pa.ern

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

Software Eningeering. Lecture 9 Design Patterns 2

Design Patterns Lecture 2

Using Design Patterns in Java Application Development

Second Midterm Review

Design Pattern Detection

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

Enterprise Integration Patterns: Designing, Building, and Deploying Messaging Solutions

Design Patterns. An introduction

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

Design Patterns. CSC207 Fall 2017

Chair of Software Engineering. Languages in Depth Series: Java Programming. Prof. Dr. Bertrand Meyer. Exercise Session 3

MSO Lecture 6. Wouter Swierstra. September 24, 2015

Object Oriented. Analysis and Design

An Introduction to Patterns

Laboratorio di Progettazione di Sistemi Software Design Pattern Creazionali. Valentina Presutti (A-L) Riccardo Solmi (M-Z)

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

Coordination Patterns

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

Avoid coupling the sender of a request to its receiver. Chain the receiving objects and pass the request along the chain until an object handles it

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

DESIGN PATTERNS SURESH BABU M ASST PROFESSOR VJIT

LECTURE NOTES ON DESIGN PATTERNS MCA III YEAR, V SEMESTER (JNTUA-R09)

Design for change. You should avoid

Template Method Structure. Template Method Example. Template Method Example. Template Method Example. Benefits of Template Method

Design Patterns. Comp2110 Software Design. Department of Computer Science Australian National University. Second Semester

Design Patterns IV Structural Design Patterns, 1

Design Patterns: Template Method, Strategy, State, Bridge

Behavioral Design Patterns Used in Data Structures Implementation

Tecniche di Progettazione: Design Patterns

S. No TOPIC PPT Slides

Design patterns. Jef De Smedt Beta VZW

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

Design Pattern and Software Architecture: IV. Design Pattern

Design Patterns and Frameworks Command

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

Transcription:

Implementing GUI context-sensitive help... ECE450 Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State ECE450 - Software Engineering II 1 ECE450 - Software Engineering II 2 Implementing GUI context-sensitive help... Context-sensitive help The user can obtain help information on any part of the interface just by clicking on it The help that is provided depends on the part of the interface that is selected and its context A button widget in a dialog box might have different help information than a similar button in the main window If no specific help information exists for that part of the interface, then the help system should display a more general help message It s therefore natural to organize help information according to its generality from the most specific to the most general The problem is that the object that ultimately provides the help is not known explicitly to the object that initiates the help request We need a way to decouple the button that initiates the help request from the objects that provide help information ECE450 - Software Engineering II 3 ECE450 - Software Engineering II 4 1

Chain of Responsibility Structure and participants Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it. Handler Defines an interface for handling requests (Optionally) implement the successor link ConcreteHandler Handles requests it is responsible for Can access its successor If the ConcreteHandler can handle the request, it does so; otherwise it forwards the request to its successor Client Initiates the request to a ConcreteHandler object on the chain ECE450 - Software Engineering II 5 ECE450 - Software Engineering II 6 Consequences Use Chain of Responsibility when... More than one object may handle a request, and the handler isn t known a priori. The handler should be ascertained automatically. You want to issue a request to one of several objects without specifying the receiver explicitly The set of objects that can handle a request should be specified dynamically Question: Is throwing exceptions the same as using the Chain of Responsibility pattern? Question: Can an object tell its successor exactly what operation to perform? If so, how? Hint: Remember Command? Reduced coupling The pattern frees an object from knowing which other object handles a request As a result, instead of objects maintaining references to all candidate receivers, they keep a single reference to their successor Added flexibility in assigning responsibilities to objects You can add or change responsibilities for handling a request by changing the chain at run-time Receipt isn t guaranteed Since a request has no explicit receiver, there s no guarantee it will be handled the request can fall off the end of the chain without ever being handled! Question: Would Chain of Responsibility work in conjunction with Composite? ECE450 - Software Engineering II 7 ECE450 - Software Engineering II 8 2

Implementing Sort() The Strategy pattern Often we need to implement a feature, but: There are several algorithms that could do the job, and we want to defer the decision of which to use......or maybe we want to use a different algorithm depending on the characteristics of the object that will run it Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it. Think of Sort() Given the characteristics of your data structure, a sorting algorithm may be more convenient than another...so it would be good if we avoid getting stuck with one algorithm in particular ECE450 - Software Engineering II 9 ECE450 - Software Engineering II 10 Structure and Participants Strategy Declares an interface common to all supported algorithms. Context uses this interface to call the algorithm defined by a ConcreteStrategy ConcreteStrategy Implements the algorithm using the Strategy interface Context Is configured with a ConcreteStrategy object Maintains a reference to a Strategy object May define an interface that lets Strategy access its data Use the Strategy pattern when... Many related classes differ only in their behavior. Strategies provide a way to configure a class with one of many behaviors You need different variants of an algorithm A class defines many behaviors, and these appear as multiple conditional statements in its operations Instead of many conditionals, move related conditional branches into their own Strategy class Remember that Decorator modifies classes behaviors by changing their skin, while Strategy modifies their behaviors by changing their guts. ECE450 - Software Engineering II 11 ECE450 - Software Engineering II 12 3

Consequences Objects may behave differently depending on their state Strategies eliminate conditional statements When different behaviors are lumped into one class, it s hard to avoid using conditional statements to select the right behavior Encapsulating the behavior in separate Strategy classes eliminates these conditional statements A choice of implementations Strategies can provide different implementations of the same behavior The client can choose among strategies with different time and space trade-offs Increased number of objects Strategies increase the number of objects in an application Sometimes you can reduce this overhead by implementing strategies as stateless objects that contexts can share ECE450 - Software Engineering II 13 ECE450 - Software Engineering II 14 Handling states Participants and structure Many programs rely heavily on tracking and changing the state of their objects Network connections Vending machines Finite state machines... For these programs, the state of the object affects their behavior E.g., a vending machine only dispenses a product if its user has given it enough cash The naive approach to handle states is to implement a lot of conditionals in one class Context Defines the interface of interest to clients Maintains an instance of a ConcreteState subclass that defines the current state State Defines an interface for encapsulating the behavior associated with a particular state of the Context ConcreteState subclasses Each subclass implements a behavior associated with a state of the Context Introducing the State pattern: Allow an object to alter its behavior when its internal state changes. The object will appear to change its class ECE450 - Software Engineering II 15 ECE450 - Software Engineering II 16 4

Wait a minute... Use the State pattern in either of the following cases: An object s behavior depends on its state, and it must change its behavior at run-time depending on that state State pattern Strategy pattern They are the same diagram!! Yes, but the patterns differ in intent: In the State pattern we have a set of behaviors encapsulated in state objects; at any time the context delegates to one of those states. Over time, the current state changes across the set of state objects to reflect the internal state of the context, so the context s behavior changes over time as well. In Strategy, the client usually specifies the strategy object that the context is composed with. Although you can change Strategy objects, often there is one that is most appropriate for a context object In general, think of Strategy as a flexible alternative to subclassing......while State is an alternative to putting lots of conditionals in your Context ECE450 - Software Engineering II 17 Operations have large, multipart conditional statements that depend on the object s state. This state is usually represented by one or more enumerated constants Often, several operations will contain this same conditional structure The State pattern puts each branch of the conditional in a separate class ECE450 - Software Engineering II 18 Consequences State localizes state-specific behavior and partitions behavior for different states Because all state-specific code lives in a State subclass, new states and transitions can be added easily by defining new subclasses It makes state transitions explicit When an object defines its current state solely in terms of internal data values, its state transitions have no explicit representation They only show up as assignments to some variables Introducing separate objects for different states makes the transitions more explicit ECE450 - Software Engineering II 19 5