Decorator Pattern The decorator pattern allows us to enclose an object inside another object. The enclosing object is called a decorator. The other object.

Slides:



Advertisements
Similar presentations
Winter 2007ACS-3913 Ron McFadyen1 Also known as publish/subscribe The essence of this pattern is that one or more objects (called observers or listeners)
Advertisements

An Online Microsoft Word Tutorial & Evaluation Begin.
Feb 2003 R McFadyen1 Contracts (Ch 13) Used to help understand requirements more completely based on assertions; assertions are applicable to any.
Jan 29, Ron McFadyen1 UML Class Diagram Examples Based on well-known patterns Exhibit ways of providing dynamic structures and behaviour.
Oct Ron McFadyen1 Collaborations Collaboration : an arrangement of classes, links, roles in a context to implement some behaviour. Name of.
Oct 22, Ron McFadyen1 Design Class Diagrams n Class diagram with – classes – associations – attributes – methods – navigability – interfaces,
March Ron McFadyen1 Command The command pattern encapsulates a request or unit of work into an object. An invoker will ask a concrete command.
Fall 2009ACS-3913 Ron McFadyen Composite Pattern Problem: How do we treat a composition structure of objects the same way as a non-composite object? Arises.
Fall 2009ACS-3913 Ron McFadyen1 Decorator Pattern The Decorator pattern allows us to enclose an object inside another object. The enclosing object is called.
Jan 2005 Ron McFadyen1 Contracts Used to help understand requirements more completely (and so may not always be necessary) based on assertions;
Sept 2004Ron McFadyen Decorator Pattern The decorator pattern allows us to enclose an object inside another object. The enclosing object is called.
Sept Ron McFadyen Sequence Diagram Objects are represented horizontally across the top of the diagram The first object is typically an Actor,
Fall 2007ACS Ron McFadyen1 Composite Pattern (see pages ) A composite is a group of objects in which some objects contain others; one object.
Design Patterns. CS351 - Software Engineering (AY2007)Slide 2 Behavioral patterns Suppose we have an aggregate data structure and we wish to access the.
Spring 2010ACS-3913 Ron McFadyen1 Command The command pattern encapsulates a request or unit of work into an object. An invoker will ask a concrete command.
Feb Ron McFadyen1 Iterator Pattern Generic UML class diagram The iterator is used to access the elements of some aggregate. The aggregate interface.
Oct Ron McFadyen Visibility Visibility: the ability of one object to see or have a reference to another object. e.g. When a register object.
Oct Ron McFadyen1 Collaborations Collaboration : an arrangement of classes, links, roles in a context to implement some behaviour. Useful for.
Winter 2015ACS Ron McFadyen1 Composite Pattern A composite is a group of objects in which some objects contain others; one object may represent.
November Ron McFadyen1 Design Class Diagrams n Class diagram with – classes – associations – attributes – methods – navigability – interfaces,
The Decorator Design Pattern (also known as the Wrapper) By Gordon Friedman Software Design and Documentation September 22, 2003.
Winter 2011ACS-3913 Ron McFadyen1 Decorator Sometimes we need a way to add responsibilities to an object dynamically and transparently. The Decorator pattern.
Sept Ron McFadyen1 Extend Relationship.
March R McFadyen1 Figure 30.2 Layers in NextGen They only have three layers in this architecture Each layer is shown as a UML Package No separate.
Department of Computer Science, York University Object Oriented Software Construction 16/09/ :52 PM 0 COSC3311 – Software Design Decorator Pattern.
Chapter 14. Copyright 2003, Paradigm Publishing Inc. CHAPTER 14 BACKNEXTEND 14-2 LINKS TO OBJECTIVES Add Borders with Borders Button Add Borders with.
Word Processing Test Review. Purpose To create a document.
Jan Ron McFadyen1 Decorator Sometimes we need a way to add responsibilities to an object dynamically and transparently. The Decorator pattern.
Decorator Explained. Intent Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to sub-classing for.
GoF: Document Editor Example Rebecca Miller-Webster.
Decorator Design Pattern Rick Mercer CSC 335: Object-Oriented Programming and Design.
Sept Ron McFadyen1 Class Diagram Begins as a conceptual or analysis class model and evolves to a design class model Used throughout the development.
November Ron McFadyen1 Composite Pattern A composite is a group of objects in which some objects contain others; one object may represent groups,
Word 2003 The Word Screen. Word 2003 Screen File Menu –Holds the options for creating a new document, opening a document, saving a document, printing.
Created by: Juan Cuellar JEOPARDY! GAME BOARD Word Outlook General Access.
1 of 4 This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS DOCUMENT. © 2006 Microsoft Corporation.
More DFDs Class 12.
Decorator Design Pattern Rick Mercer CSC 335: Object-Oriented Programming and Design.
S.Ducasse Stéphane Ducasse 1 Decorator.
Decorator Design Pattern Phillip Shin. Overview Problem Solution Example Key points.
Document Control Template Editors Brad Adamczyk Template Editor Bands Bands create document layout Header, data, footer Order not critical.
On Line Microsoft Word Tutorial & Evaluation Begin.
View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user interface element (the user interface.
CIW LESSON 7 PART A. INTRODUCTION TO BUSINESS ELECTRONIC MAIL The use of has given rise to the term ______________________, which is a slang term.
Introduction to Microsoft publisher
At the end of each day the evening manager at each store enters a code into the cash register, after which the cash register connects to the central computer.
Used to help understand requirements more completely
Stream Agent Training March 2014.
Introduction to Microsoft publisher
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University
Microsoft Office Word 2003.
Prepared By Sidra Noureen
Lab 7: Business Process Modeling Notation (BPMN)
Outlook 2003.
CIW Lesson 7 Part A Name: _______________________________________
Composite Pattern Oct 7, 2003 A composite is a group of objects in which some objects contain others; one object may represent groups, and another.
(Includes setup) FAQ ON DOCUMENTS (Includes setup)
Decorator Pattern Intent
Figure 30.2 Layers in NextGen
Composite Pattern Context:
08/15/09 Decorator Pattern Context: We want to enhance the behavior of a class, and there may be many (open-ended) ways of enhancing the class. The enhanced.
1: click on the check box in front of the document(s) you would like to share (eg : Case Analysis/Transmittal Letter/Notification letter) . A green bar.
Deepak Shenoy Agni Software
.
Class Diagram Begins as a conceptual or analysis class model and evolves to a design class model Used throughout the development process. More detail added.
Learning the Basics of Microsoft Word 2010 for Microsoft Windows
(Includes setup) FAQ ON DOCUMENTS (Includes setup)
Activity 1 - Chapter 5 -.
Some examples of simple business rules:
Recursive Relationship
Presentation transcript:

Decorator Pattern The decorator pattern allows us to enclose an object inside another object. The enclosing object is called a decorator. The other object is the component, it is the decorated object. The decorator conforms to the interface of the enclosed component and so its presence is transparent to the components clients. The decorator forwards requests to the component, but may perform some processing before/after doing so. Oct 2003 Ron McFadyen 91.3913

:border would draw itself; Decorator Pattern e.g. In a windowing environment, scrolling bars, borders, etc. could be decorators on top of the text view of a document. :border :scrollBar :textView component component draw() draw() draw() When it’s necessary for the document to appear (to draw itself), the draw message would be sent to :border and then: :border would draw itself; :border would send the draw message to :scrollBar which would draw itself; :scrollBar would send the draw message to :textView. Oct 2003 Ron McFadyen 91.3913

Generic UML class diagram 1 Client Component Decorator Pattern How would you characterize the components? Generic UML class diagram 1 Client Component Operation() Decorated Decorator Operation() Operation() other() Decorator1 Decorator2 … Decorator n Oct 2003 Ron McFadyen 91.3913

Decorator Pattern - example Consider a the NextGenPOS system. It must produce a sales receipt. A sales receipt will have a header and a footer, and perhaps … more than one header … more than one footer. Suppose we add coupons to the sales receipt … perhaps based on the products purchased / the season / information about the customer / etc. Time of day header Product2 coupon header Line item 1 Line item 2 Line item 3 … Money saved footer Oct 2003 Ron McFadyen 91.3913

Decorator Pattern - example UML class diagram 1 sale DecoratedReceipt print() All classes, in this application of the decorator pattern, implement the print method receipt Decorator print() print() other() timeOfDay productCoupon moneySaved Oct 2003 Ron McFadyen 91.3913

Decorator Pattern – example object diagram a sale object is related to a receipt, but the receipt is decorated with headers and footers (as this particular receipt requires) s:sale h1: timeOfDay h2:productCoupon decorators f1: moneySaved r: receipt Oct 2003 Ron McFadyen 91.3913

Decorator Pattern - example Printing the receipt s:sale h1: timeOfDay h2:productCoupon f1: moneySaved r: receipt print() print() printTime() print() printCoupon() print() print() printNote() Oct 2003 Ron McFadyen 91.3913

Exercise Suppose we have simple stream files and various actions that can be applied to them sequentially: encrypt, decrypt, compress, decompress, … A file is encrypted and compressed :compress :encrypt :aFile A file is decompressed and decrypted :decrypt :decompress :bFile Oct 2003 Ron McFadyen 91.3913

Decorator Pattern - exercise UML class diagram 1 wordProcessor DecoratedFile write() All classes, in this application of decorator pattern, implement the write method file Decorator write() write() other() decrypt encrypt compress decompress write decrypt write encrypt write compress write decompress Oct 2003 Ron McFadyen 91.3913

Decorator Pattern - exercise Saving the file :wordProcessor :compress :encrypt :aFile save() write() compress() write() encrypt() write() Oct 2003 Ron McFadyen 91.3913