PH Chapter 3 Thanks for the Memory Leaks Pushme-Pullyu (pp

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

Chain of Responsibility Pattern Gof pp Yuyang Chen.
CSE 432: Course Summary Course Summary: CSE specific GoF/PH design patterns’ structure & content How requirements, design forces, and patterns interact.
GoF Sections 2.7 – 2.9 More Fun with Lexi. Lexi Document Editor Lexi tasks discussed:  Document structure  Formatting  Embellishing the user interface.
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
Computer Science 313 – Advanced Programming Topics.
DESIGN PATTERNS OZGUR RAHMI DONMEZ.
Matt Klein 7/2/2009.  Intent  Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request.
More Interfaces, Dynamic Binding, and Polymorphism Kirk Scott.
The Bridge Pattern Guang Hu February Overview MotivationMotivation ParticipantsParticipants  Structure  Applicability  Benefits  Drawbacks 
Software Design & Documentation – Design Pattern: Command Design Pattern: Command Christopher Lacey September 15, 2003.
Copyright © 1995 –2004 Active Frameworks Inc. - All Rights Reserved - V2.0Behavioral Patterns - Page L8-1 PS95&96-MEF-L15-1 Dr. M.E. Fayad Creationa l.
BehavioralCmpE196G1 Behavioral Patterns Chain of Responsibility (requests through a chain of candidates) Command (encapsulates a request) Interpreter (grammar.
Command Pattern Chihung Liao Cynthia Jiang. Waiter Order Execute() Hamburger Execute() Hot Dogs Execute() Fries Execute() Cook Make Food()
GoF Sections 2.7 – 2.9 More Fun with Lexi. Lexi Document Editor Lexi tasks discussed:  Document structure  Formatting  Embellishing the user interface.
Reuse Activities Selecting Design Patterns and Components
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Larman, chapters 25 and 26 CSE432 Object-Oriented Software Engineering Glenn D. Blank, Lehigh University Pure Fabrication and “Gang of Four” Design Patterns.
BY VEDASHREE GOVINDA GOWDA
Behavioral Patterns  Behavioral patterns are patterns whose purpose is to facilitate the work of algorithmic calculations and communication between classes.
Singleton Christopher Chiaverini Software Design & Documentation September 18, 2003.
BDP Behavioral Pattern. BDP-2 Behavioral Patters Concerned with algorithms & assignment of responsibilities Patterns of Communication between Objects.
Design patterns. What is a design pattern? Christopher Alexander: «The pattern describes a problem which again and again occurs in the work, as well as.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
CS 210 Introduction to Design Patterns September 28 th, 2006.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Design Patterns Part two. Structural Patterns Concerned with how classes and objects are composed to form larger structures Concerned with how classes.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
Command. RHS – SOC 2 Executing a command Executing a command appears simple at first, but many details to consider: –Who creates a command? –Who invokes.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VII Observer, Command, and Memento.
Pure Fabrication and “Gang of Four” Design Patterns
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
Lexi case study (Part 2) Presentation by Matt Deckard.
GoF Sections Design Problems and Design Patterns.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
ECE450S – Software Engineering II
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Command Pattern.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
BEHAVIORAL PATTERNS 13-Sep-2012 Presenters Sanjeeb Kumar Nanda & Shankar Gogada.
Example to motivate discussion We have two lists (of menu items) one implemented using ArrayList and another using Arrays. How does one work with these.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Chapter 8 Object Design Reuse and Patterns. More Patterns Abstract Factory: Provide manufacturer independence Builder: Hide a complex creation process.
Reference – Object Oriented Software Development Using Java - Jia COP 3331 Object Oriented Analysis and Design Chapter 10 – Patterns Jean Muhammad.
Behavioural Patterns GoF pg Iterator GoF pg. 257 – 271 Memento GoF pg By: Dan Sibbernsen.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
CSE 432: Thanks for the memory leaks, Pushme-Pullyu, and Command Summary of “Thanks for the Memory Leaks” “Left-over” design forces from Type Laundering.
Module 9. Dealing with Generalization Course: Refactoring.
Command. RHS – SWC 2 Executing a command Executing a command appears simple at first, but many details to consider: –Who creates a command? –Who invokes.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Command Pattern. Intent encapsulate a request as an object  can parameterize clients with different requests, queue or log requests, support undoable.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Jim Fawcett CSE776 – Design Patterns Summer 2005
Chapter 10 Design Patterns.
Software Design Patterns
Don’t reinvent the wheel
Structural Patterns Structural patterns control the relationships between large portions of your applications. Structural patterns affect applications.
Factory Patterns 1.
Behavioral Design Patterns
Software Design and Architecture
More Interfaces, Dynamic Binding, and Polymorphism
object oriented Principles of software design
Command Pattern.
Programming Design Patterns
Design Patterns Satya Puvvada Satya Puvvada.
CSE 432 Presentation GoF: Factory Method PH: “To Kill a Singleton”
Behavioral Patterns Part-I introduction UNIT-VI
Design Patterns Part 2: Factory, Builder, & Memento
12. Command Pattern SE2811 Software Component Design
Informatics 122 Software Design II
The Command Design Pattern
Presentation transcript:

PH Chapter 3 Thanks for the Memory Leaks Pushme-Pullyu (pp PH Chapter 3 Thanks for the Memory Leaks Pushme-Pullyu (pp. 110-121) GoF Command Pattern (pp. 233-242) By: Dan Sibbernsen 25/06/09

Thanks for the Memory Leaks Overview Dynamically created cursors, how do we track them for deletion? Need to avoid leaking memory, responsibility lies within the Client for deletion Solution Bridge Pattern (aka Handle-Body)

Bridge Introduce a CursorImp class Pg. 100-101 (implementation) Serves as an abstract Memento class, rather than Cursor Cursor serves as a Handle to CursorImp, and we increment a reference count inside Handle every time the constructor is called Pg. 100-101 (implementation)

Pushme-Pullyu Problem Pull Push Having to downcast a type to something application specific Pull Consumer, or the application, pulls information from the framework Push Consumer waits for the Producer

Design Questions Push Or Pull? Push: Makes it easier to implement Consumer Pull: Makes it easier to implement Producer

Command Pattern Intent Motivation Provides for undoable operations Able to pass requests as objects, gives added flexibility, such as queuing or logging requests. Motivation To decouple issuing requests from both the operation being done and the receiver.

Class Diagram

Class Responsibilities Command Abstract interface for executing operations ConcreteCommand Binds the Receiver object to an Action Client Instantiates a ConcreteCommand with a Receiver Invoker “Tells the command to carry out the request” Receiver Can perform the operation defined by the Command

Interaction Diagram

Consequences (Good) Decouples requester from operation of the class. Command can be manipulated for the greater good (which, of course, is extensibility) Can use the composite pattern to treat all commands uniformly New commands can be added easily

Implementation Details How Intelligent should a command be? Very simple: merely a binding between receiver and the request’s action Very ingrained: command implements everything without delegating to any receiver Defines commands that don’t fit into any existing classes When no suitable receiver exists When the command knows its receiver implicitly

Implementation Details Supporting Undo and Redo Keep a function that can reverse the execution Possibly need a ConcreteCommand to store state To support multiple levels, we need to store a list of these commands

Implementation Details Avoiding error accumulation in the undo process Undo/Redo can change the state of the program, and have errors accumulate that will change the state. Memento Pattern can be used to store state of the program at the command’s execution to guarantee it is in the original state. Can be done without exposing class internals

Implementation Details Using C++ Templates Can be used in cases where actions aren’t undoable, and don’t require arguments Eliminates need for creating a subclass for every action/receiver pair (sample code on page 239)

Related Patterns Composite Memento Prototype