CSE 332: Design Patterns Review: Design Pattern Structure A design pattern has a name –So when someone says “Adapter” you know what they mean –So you can.

Slides:



Advertisements
Similar presentations
Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
Advertisements

MicroKernel Pattern Presented by Sahibzada Sami ud din Kashif Khurshid.
 Recent researches show that predicative programming can be used to specify OO concepts including classes, objects, interfaces, methods, single and multiple.
Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
Design Patterns CMPS Design Patterns Consider previous solutions to problems similar to any new problem ▫ must have some characteristics in common.
Reza Gorgan Mohammadi AmirKabir University of Technology, Department of Computer Engineering & Information Technology Advanced design.
Object Oriented System Development with VB .NET
BehavioralCmpE196G1 Behavioral Patterns Chain of Responsibility (requests through a chain of candidates) Command (encapsulates a request) Interpreter (grammar.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Design Patterns.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Object-oriented design CS 345 September 20,2002. Unavoidable Complexity Many software systems are very complex: –Many developers –Ongoing lifespan –Large.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Chapter 25 More Design Patterns.
BDP Behavioral Pattern. BDP-2 Behavioral Patters Concerned with algorithms & assignment of responsibilities Patterns of Communication between Objects.
Design Patterns.
An Introduction to Software Architecture
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
CSE 332: Design Patterns (Part I) Introduction to Design Patterns Design patterns were mentioned several times so far –And the Singleton Pattern was discussed.
“A labor of love” (Multicast Pattern) Chapter 4 (pages or ) Chris Gordon.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Patterns and Reuse. Patterns Reuse of Analysis and Design.
GoF Sections Design Problems and Design Patterns.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
ECE450S – Software Engineering II
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
CSE 332: Design Patterns Review: Design Pattern Structure A design pattern has a name –So when someone says “Adapter” you know what they mean –So you can.
Design Patterns. OO-Concepts Don’t rewrite code Encapsulation Inheritance Write flexible code.
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.
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Manali Joshi1 The Observer Design Pattern Presented By: Manali Joshi.
Behavioral Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
More Design Patterns From: Shalloway & Trott, Design Patterns Explained, 2 nd ed.
Using Software Design Patterns Bill Anderson. About me Fox developer since 1987 Fox developer since 1987 Program Director, Los Angeles Visual Foxpro Developers.
1 Chapter 5:Design Patterns. 2 What are design pattern?  Schematic description of design solution to recurring problems in software design and,  Reusable.
BEHAVIORAL PATTERNS 13-Sep-2012 Presenters Sanjeeb Kumar Nanda & Shankar Gogada.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 31. Review Creational Design Patterns – Singleton Pattern – Builder Pattern.
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.
CSE 332: Design Patterns Introduction to Design Patterns You’ve seen design patterns several times this semester –The Iterator pattern has been discussed.
The Strategy Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
L10: Model-View-Controller General application structure. User Interface: Role, Requirements, Problems Design patterns: Model – View – Controller, Observer/Observable.
CSE 332: Design Patterns (Part II) Last Time: Part I, Familiar Design Patterns We’ve looked at patterns related to course material –Singleton: share a.
Behavioural Patterns GoF pg Iterator GoF pg. 257 – 271 Memento GoF pg By: Dan Sibbernsen.
The Memento Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
1 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Introduction to Design Patterns.
OBSERVER PATTERN OBSERVER PATTERN Presented By Presented By Ajeet Tripathi ISE
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
1 Use Cases Object-Oriented Modeling and Design with UML (Second Edition) Blaha & Rumbaugh Sections 7.1, 8.1.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Design Patterns: MORE Examples
Introduction to Design Patterns
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
Software Design Patterns
Introduction to Design Patterns
Java Beans Sagun Dhakhwa.
Observer Design Pattern
object oriented Principles of software design
What’s a Design Pattern?
Advanced Programming Behnam Hatami Fall 2017.
Behavioral and Structural Patterns
Patterns.
Review: Design Pattern Structure
Introduction to Design Patterns
Adapter Design Pattern
Presentation transcript:

CSE 332: Design Patterns Review: Design Pattern Structure A design pattern has a name –So when someone says “Adapter” you know what they mean –So you can communicate design ideas as a “vocabulary” A design pattern describes the core of a solution to a recurring design problem –So you don’t have to reinvent known design techniques –So you can benefit from others’ (and your) prior experience A design pattern is capable of generating many distinct design decisions in different circumstances –So you can apply the pattern repeatedly as appropriate –So you can work through different design problems using it

CSE 332: Design Patterns Three Design Patterns Involving Classes Adapter (structural) –Converts an interface you have into one you want Memento (behavioral) –Externalizes the state of an object Observer (behavioral) –Tells objects about changes in another object

CSE 332: Design Patterns Structural Patterns Help define fixed structural relationships –Between classes, and their associations Emphasis on the class diagrams Example –Adapter pattern

CSE 332: Design Patterns Inconsistent Interfaces Challenge –Different code bases are often written by different developers, at different times, with different design goals –Interfaces expected by one piece of code are not always the same as those provided by the other code that’s available Motivates use of the Adapter pattern –Provides a class that exposes the interface that’s needed –That interface is implemented using calls to methods of the existing object(s) –A related pattern called “Wrapper Façade” provides a similar capability by wrapping functions (e.g., socket calls, etc.)

CSE 332: Design Patterns Adapter Pattern Problem –Have an object with an interface that’s close to (but is not exactly) what we need Context –Want to re-use an existing class –Can’t change its interface –It’s impractical to extend class hierarchy more generally Solution Core –Wrap a particular class or object with the interface needed (2 forms: class form and object forms)

CSE 332: Design Patterns Adapter Structure (Class Form) Interface abstract base class provides desired interface Impl concrete class provides the implementation Adapter glues them together via inheritance InterfaceImpl method () = 0;impl_method (); Adapter method () { impl_method (); }; public private

CSE 332: Design Patterns Adapter Structure (Object Form) Interface abstract base class provides desired interface Impl concrete class provides the implementation Adapter glues them together via delegation Interface Impl method () = 0; impl_method (); Adapter method () { impl_->impl_method(); }; impl_

CSE 332: Design Patterns Behavioral Patterns Help define dynamic behavioral relationships –Between objects at run-time Emphasis is on interactions among objects Examples –Memento pattern –Observer pattern

CSE 332: Design Patterns Adding State Persistence Challenge –Want to save and restore an object’s state –For example, between different runs of a program Motivates use of the Memento pattern –Serialize an object’s state into an opaque “cookie” –Format of cookie can be tailored to storage format –Can send it to a file, a caretaker object, another computer –Can reconstitute object from its memento later/elsewhere

CSE 332: Design Patterns Memento Pattern Problem –Want to externalize state of an object without violating encapsulation Context –A snapshot of object state is needed –Providing a state interface would violate encapsulation Solution Core –Create a memento class with methods to get, set state –Provide an opaque representation of state itself Consequences –Can use memento to send object state over a socket, save it in a file, put it into a checkpoint/undo stack, etc.

CSE 332: Design Patterns Inter-dependent Object Behaviors Challenge: need to coordinate object state changes –For example, a sensor may record current temperature –Other objects (e.g., thermostat) need to know when the temperature changes Motivates use of the Observer pattern –Helps to keep objects mostly independent –Separates registration, notification, and actions –But, still allows appropriate coordination among objects

CSE 332: Design Patterns Observer Pattern Problem –Need to update multiple objects when the state of one object changes Context –Multiple objects depend on the state of one object –Set of dependent objects may change at run-time Solution core –Allow dependent objects to register with object of interest, notify them of updates when state changes Consequences –When observed object changes others are notified –Useful for user interface programming, other applications

CSE 332: Design Patterns Observer Pattern Behavior > register() > notify() ∆ state register() update() (optional)