Behavioural Patterns GoF pg. 221 -222 Iterator GoF pg. 257 – 271 Memento GoF pg. 283-291 By: Dan Sibbernsen.

Slides:



Advertisements
Similar presentations
Welcome to. Who am I? A better way to code Design Patterns ???  What are design patterns?  How many are there?  How do I use them?  When do I use.
Advertisements

Matt Klein. Decorator Pattern  Intent  Attach Additional responsibilities to an object by dynamically. Decorators provide a flexible alternative to.
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.
C15: Design Patterns Gamma,Helm,Johnson,Vlissides (GOF)
DESIGN PATTERNS OZGUR RAHMI DONMEZ.
Iterators T.J. Niglio Computer & Systems Engineering Fall 2003 Software Design & Documentation Object Behavioral.
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.
Design Patterns CS is not simply about programming
Design Patterns. CS351 - Software Engineering (AY2007)Slide 2 Behavioral patterns Suppose we have an aggregate data structure and we wish to access the.
Software Design and Documentation Individual Presentation: Composite Pattern 9/11/03.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
GoF Sections 2.7 – 2.9 More Fun with Lexi. Lexi Document Editor Lexi tasks discussed:  Document structure  Formatting  Embellishing the user interface.
Memento Page 283 Jason Penny. Memento Behavioral Pattern Behavioral Pattern Intent: Intent: Without violating encapsulation, capture and externalize an.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VI Composite, Iterator, and Visitor Patterns.
Behavioral Pattern: Memento C h a p t e r 5 – P a g e 179 Objects frequently expose only some of their internal state using public methods, but there.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Behavioral Patterns C h a p t e r 5 – P a g e 128 BehavioralPatterns Design patterns that identify and realize common interactions between objects Chain.
BDP Behavioral Pattern. BDP-2 Behavioral Patters Concerned with algorithms & assignment of responsibilities Patterns of Communication between Objects.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
More Design Patterns In Delphi Jim Cooper Falafel Software Session Code: D3.03 Track: Delphi.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Behavioral Design Patterns Morteza Yousefi University Of Science & Technology Of Mazandaran 1of 27Behavioral 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.
Computing IV Singleton Pattern Xinwen Fu.
Objects to Protect Private Details: Memento and Iterator Snarf the iterator code for today’s class.
Structural Design Patterns
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.
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.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Strategy Pattern.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
CS212: Object Oriented Analysis and Design Lecture 37: Design Pattern.
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 Introduction
BEHAVIORAL PATTERNS 13-Sep-2012 Presenters Sanjeeb Kumar Nanda & Shankar Gogada.
CS212: Object Oriented Analysis and Design Lecture 39: Design Pattern-III.
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.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
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.
The Memento Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Design Patterns: Behavioral Design Patterns General and reusable solutions to common problems in software design Software University
Duke CPS Programming Heuristics l Identify the aspects of your application that vary and separate them from what stays the same ä Take what varies.
COMPOSITE PATTERN NOTES. The Composite pattern l Intent Compose objects into tree structures to represent whole-part hierarchies. Composite lets clients.
Overview of Behavioral Patterns ©SoftMoore ConsultingSlide 1.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Jim Fawcett CSE776 – Design Patterns Summer 2005
Design Patterns Spring 2017.
Chapter 10 Design Patterns.
Software Design Patterns
Introduction to Design Patterns
Behavioral Design Patterns
Observer Design Pattern
Foundations of Software Engineering Patterns - Introduction
Memento Pattern F 羅世東 F 李天彥 F 鄧義佐 F 林尚霖
Memento Design Pattern
Design Patterns in Game Design
PH Chapter 3 Thanks for the Memory Leaks Pushme-Pullyu (pp
Review: Design Pattern Structure
The iterator and memento patterns
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
Memento Pattern 1.
Software Design Lecture : 39.
Iterator Design Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014
Presentation transcript:

Behavioural Patterns GoF pg Iterator GoF pg. 257 – 271 Memento GoF pg By: Dan Sibbernsen

Overview Behavioural – Concerned with algorithms and responsibilities among objects. – Also concerned with methods of communication between them – Allow you to put your “interconnected” hat on while taking off your “control” hat.

Iterator Intent – Provide a means to Iterate through a series of nodes in specific way(s) Motivation – To traverse lists of information without having to know anything too specific about the objects – To implement multiple algorithms to traverse those nodes.

Class Diagram

Iterator:Implementation Who Controls the Iteration? – External Iterator Client controls iteration Client must explicitly request next() on each node – Internal Iterator Iterator controls iteration Client hands an operation to the Iterator, Iterator tells every child in the aggregate to perform it.

Implementation Benefits External Iterator – More flexible than Internal. Can compare 2 collections easily Internal Iterator – Easier to use, as they define the iteration logic for you. Makes portability easier.

Who defines the traversal Algorithm? Algorithm can be held by a class outside of the Iterator. It could be held by the aggregate can hold it. – Called “the cursor.” – Allows the algorithm to access private members of the aggregate (and not break encapsulation) Algorithm is held by the iterator – Allows algorithms to be swapped out easily.

How Robust is the Iterator? If an iterator is robust it – Will allow for removal of nodes in the middle of traversal. – It does this through registering the iterator with the aggregate. If any nodes are removed, it is notified.

Additional Iterator Operations All come with first, next, isdone, and currentItem Previous – Goes to the previous node that was iterated – Can be helpful in certain situations SkipTo – Skips to a certain node. – Goes to a node matching specific criteria

Using Polymorphic Iterators in c++ Drawbacks – Allocated dynamically by a factory method. – Client is responsible for deleting them. Can be error prone due to multiple levels of calls, and also because of exceptions Proxy can be used to remedy this. Only use them when Polymorphism is required.

Iterators may have privileged access Makes coupling tighter between Iterator and Aggregate Can be problematic if there are multiple iterators you want to apply – Solution: make private iterator-specific functions “protected” so that only Iterator subclasses can access them

Iterators for composites Use an Internal iterator to keep track of the levels-deep it has traversed. This happens recursively so everything is stored on the stack.

Null Iterators Makes traversal of Composite classes easier. Always returns IsDone() as true.

Related Patterns Composite Factory Method Memento

Consequences (good) “Supports variations in the traversal of an aggregate.” “Iterators simplify the Aggregate interface.” “More than one traversal can be pending on an aggregate.”

Memento Intent – “Without violating encapsulation, capture and externalize an object’s internal state so that the object can be restored to this state later.” Motivation – When we want to store off an object’s internal state without adding any complication to the object’s interface. – Perhaps for an undo mechanism

Class Diagram

Undo Mechanism Complications Constraint-Solver problem – Uses multiple levels deep of objects to draw objects. – What if we want to support undo but can’t localize the changes to just one class? – Propose a Memento that gathers information from objects contained in a certain class

Applicability Use this – when you want to save state on a hierarchy’s elements. – When the hierarchy’s interface would be broken if implementation details were exposed.

Participants Memento – stores the state of the Originator Originator – Creates the memento – “Uses the memento to restore its internal state” CareTaker – Keeps track of the Memento – Never uses the Memento’s Interface to the Originator

Collaboration Pg. 286 (can’t find image) Caretaker requests a memento from an Originator. Caretaker passes back memento. Originator uses it to restore state.

Consequences (good) “Preserves Encapsulation Boundaries” “It simplifies Originator” You can name your class “mementos_TheFreshMaker”!!!

Consequences (bad) Might be expensive Difficulty defining interfaces to keep Originator encapsulated Hidden costs in caring for mementos – Caretaker could have to keep track of a lot of information for the memento You can name your class “mementos_TheFreshMaker” =(

Implementation Language Support – C++ lets you call Originator a friend of Memento, thus giving it access to all private members of Memento that it needs

Storing Incremental Changes If storing state happens incrementally, then we can just record the changes of what’s happened in a new memento object. This helps with memory difficulties.

Related Patterns Command Iterator