Design Patterns Part 2: Builder & Memento

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

DESIGN PATTERNS OZGUR RAHMI DONMEZ.
Memento Kendra Kachelein Maureen Thomas. Definition The memento captures and externalizes an object’s internal state, so the object can be restored to.
Design Patterns Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Design Pattern Course Builder Pattern 1 Mahdieh Monzavi AmirKabir University of Technology, Department of Computer Engineering & Information Technology.
Design Patterns CS is not simply about programming
Design Patterns. What are design patterns? A general reusable solution to a commonly occurring problem. A description or template for how to solve a problem.
March Ron McFadyen1 Design Patterns In software engineering, a design pattern is a generally repeatable solution to a commonly-occurring problem.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
Adapters Presented By Zachary Dea. Definition A pattern found in class diagrams in which you are able to reuse an ‘adaptee’ class by providing a class,
Memento Page 283 Jason Penny. Memento Behavioral Pattern Behavioral Pattern Intent: Intent: Without violating encapsulation, capture and externalize an.
Design Patterns Ric Holt & Sarah Nadi U Waterloo, March 2010.
Builder A Creational Design Pattern A Presentation by Alex Bluhm And.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Behavioral Patterns  Behavioral patterns are patterns whose purpose is to facilitate the work of algorithmic calculations and communication between classes.
BDP Behavioral Pattern. BDP-2 Behavioral Patters Concerned with algorithms & assignment of responsibilities Patterns of Communication between Objects.
ADAPTER PATTERN BY Sravanthi Karumanchi. Structure Pattern Structure patterns are concerned with how classes and objects are composed to form large structures.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Object Oriented Software Engineering Chapter 16 and 17 review 2014/06/03.
CSE 403 Lecture 14 Design Patterns. Today’s educational objective Understand the basics of design patterns Be able to distinguish them from design approaches.
CSE 432: Design Patterns Introduction What’s a Pattern? What’s an Idiom? According to Alexander, a pattern: –Describes a recurring problem –Describes the.
Unit 4 Object-Oriented Design Patterns NameStudent Number CAI XIANGHT082182A KYAW THU LINHT082238Y LI PENGFEIHT082220L NAUNG NAUNG LATTHT082195L PLATHOTTAM.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Design Patterns -- Omkar. Introduction  When do we use design patterns  Uses of design patterns  Classification of design patterns  Creational design.
Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared.
C# and Design Patterns Builder Pattern. 2 C# and Design Patterns Builder Pattern Object creational pattern Object creational pattern Separates construction.
DESIGN PATTERNS -BEHAVIORAL PATTERNS WATTANAPON G SUTTAPAK Software Engineering, School of Information Communication Technology, University of PHAYAO 1.
Builder An Object Creational Pattern Tim Rice CSPP51023 March 2, 2010.
Proxy Design Pattern By:Diksha Agarwal.
Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Advanced Object-oriented Design Patterns Creational Design Patterns.
Memento Design Pattern Lee Lisle. Overview Why would we use Memento? Examples of Memento How to implement Memento.
Reference – Object Oriented Software Development Using Java - Jia COP 3331 Object Oriented Analysis and Design Chapter 10 – Patterns Jean Muhammad.
The Memento Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Overview of Creational Patterns ©SoftMoore ConsultingSlide 1.
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Jim Fawcett CSE776 – Design Patterns Summer 2005
Design Patterns Spring 2017.
The Object-Oriented Thought Process Chapter 15
Chapter 10 Design Patterns.
Don’t reinvent the wheel
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Introduction to Design Patterns
How to be a Good Developer
Design Patterns Part 1: Observer, Singleton, & Adapter
How to be a Good Developer
Memento Design Pattern
object oriented Principles of software design
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
PH page GoF Singleton p Emanuel Ekstrom.
Adapter Pattern 1.
CSE 403 Software Design.
PH Chapter 3 Thanks for the Memory Leaks Pushme-Pullyu (pp
The iterator and memento patterns
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
Design Patterns Part 2: Factory, Builder, & Memento
CS 350 – Software Design Singleton – Chapter 21
Adapter Design Pattern
Informatics 122 Software Design II
Adapter Pattern Jim Fawcett
Adapter Pattern Jim Fawcett
Presentation transcript:

Design Patterns Part 2: Builder & Memento

Last time Observer: Singleton: Adapter: Keeping up with the times Making sure there is only one Adapter: Filling the gaps

Today’s Objectives: Two more patterns Builder Memento

Running Example: Tiger Dining

Recall: Adapter Pattern Solution to Support Multiple Payment Methods

Goal: To add additional payment methods PaymentsController new create … DiningDollars charge(uid) …

Solution: Adapter Interface which bridge a gap in payment methods Key objects are Target, Adapter and Adaptee Target request() Client Adapter request() Adaptee specificrequest()

DiningDollarsAdapter PaymentProcessor process_payment() PaymentsController … DiningDollarsAdapter process_payment() VisaPayAdapter process_payment() DiningDollars charge(uid) VisaPay pay(debitcard, cvv, exp)

Control Flow PaymentsController create

Control Flow PaymentsController create vpa:VisaPayAdapter new

Control Flow PaymentsController create new vpa:VisaPayAdapter new vp:VisaPay new

Control Flow PaymentsController create new vpa:VisaPayAdapter new vp:VisaPay new process_payment

Visa processes the payment Control Flow PaymentsController create new vpa:VisaPayAdapter new vp:VisaPay process_payment pay Visa processes the payment

Yuck!

Clean up payment initialization Design problem: Clean up payment initialization

Solution: Separate construction code Needs to separate construction of a complex object Same construction interface creates different representation

Solution: Builder Director construct() Builder build() ConcreteBuilder Product

… PaymentsController create() PaymentProcessorBuilder build(params) DiningDollarsAdapterBuilder build(params) VisaPayAdapterBuilder build(params) DiningDollarsAdapter VisaPayAdapter

Goal: Implement Builder pattern Step 1: Create Builder Classes Step 2: Move constructor code out of controller inside build Step 3: instantiate build class inside construct

Goal: Implement Builder pattern Step 1: Create Builder Classes Step 2: Move constructor code out of controller inside build Step 3: instantiate build class inside construct

Goal: Implement Builder pattern Step 1: Create Builder Classes Step 2: Move constructor code out of controller inside build Step 3: instantiate build class inside construct

Goal: Implement Builder pattern Step 1: Create Builder Classes Step 2: Move constructor code out of controller inside build Step 3: instantiate build class inside construct

vpab:VisaPayAdapterBuilder Control Flow : PaymentsController create new vpab:VisaPayAdapterBuilder build

vpab:VisaPayAdapterBuilder Control Flow : PaymentsController create new vpab:VisaPayAdapterBuilder build new vpa:VisaPayAdapter process_payment

Delete from cart and Undo Design problem: Delete from cart and Undo

Cannot retrieve back

OrdersController new create … destroy

Solution: Memento Needs to store the state of the order Caretaker Originator state … create_memento(): Memento set_memento(memento) Memento state … getters and setters … Caretaker

OrderMementoCaretaker Originator state … create_memento(): Memento set_memento(memento) Memento state … getters and setters … Caretaker Order … create_memento set_memento(version) OrderMemento order … initialize OrderMementoCaretaker

Control Flow: destroy : OrdersController destroy

Goal: Implement Memento pattern

omc: OrderMementoCaretaker Control Flow: destroy : OrdersController destroy omc: OrderMementoCaretaker or: Order

Goal: Implement Memento pattern

Goal: Implement Memento pattern

Goal: Implement Memento pattern

Control Flow: destroy : OrdersController omc: OrderMemento Caretaker new new or: Order destroy

Goal: Implement Memento pattern

Goal: Implement Memento pattern

Control Flow: destroy : OrdersController omc: OrderMemento Caretaker new new or: Order destroy create_memento om:OrderMemento new

Goal: Implement Memento pattern

Goal: Implement Memento pattern

Goal: Implement Memento pattern

Control Flow: destroy : OrdersController omc: OrderMemento Caretaker new new or: Order destroy create_memento new om:OrderMemento push_memento

Goal: Implement Memento pattern

Goal: Implement Memento pattern

Control Flow: undo : OrdersController omc: OrderMemento Caretaker new or: Order pop_memento set_memento new om:OrderMemento save

Goal: Implement memento pattern Order “create_memento” and “set_memento” OrderMemento initialize OrderMementoCaretaker “push_memento” and “pop_memento”

Memento : Examples Editor (Notepad, Sublime, Notepad++) Provides features of undo and redo

For more design patterns, see the “Gang of Four” book (GoF)