Jan 200692.3913 Ron McFadyen1 Decorator Sometimes we need a way to add responsibilities to an object dynamically and transparently. The Decorator pattern.

Slides:



Advertisements
Similar presentations
Winter 2007ACS-3913 Ron McFadyen1 Duck Example Consider the text example (up to page 6). Each type of duck is a subclass of Duck Most subclasses implement.
Advertisements

Decorator Pattern Applied to I/O stream classes. Design Principle Classes should be open for extension, but closed for modification –Apply the principle.
Chapter 3: The Decorator Pattern
Decorator Pattern Lecture Oo29 Artificial Life Simulation.
CS 210 Introduction to Design Patterns September 12 th, 2006.
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.
March Ron McFadyen1 Design Patterns In software engineering, a design pattern is a generally repeatable solution to a commonly-occurring problem.
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.
Marcelo Santos 1 Design Patterns Object Oriented Programming Advanced Course 2007.
Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 1 Object-Oriented Analysis and Design - CDT309 Period 4, Spring 2008 More design patterns.
Fall 2009ACS-3913 Ron McFadyen1 Decorator Pattern The Decorator pattern allows us to enclose an object inside another object. The enclosing object is called.
Feb Ron McFadyen1 Iterator Pattern Recall Generic UML class diagram The iterator is used to access the elements of some aggregate. The aggregate.
Feb Ron McFadyen1 Factory Method Iterator Example : Java collection classes represent an example of the Factory Method design pattern. The.
Sept 2004Ron McFadyen Decorator Pattern The decorator pattern allows us to enclose an object inside another object. The enclosing object is called.
Fall 2007ACS Ron McFadyen1 Composite Pattern (see pages ) A composite is a group of objects in which some objects contain others; one object.
March Ron McFadyen1 Design Patterns In software engineering, a design pattern is a generally repeatable solution to a commonly-occurring problem.
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 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.
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.
Spring 2010ACS-3913 Ron McFadyen1 Duck Example Consider the text example (up to page 6). Each type of duck is a subclass of Duck Most subclasses implement.
Design Patterns.
Department of Computer Science, York University Object Oriented Software Construction 16/09/ :52 PM 0 COSC3311 – Software Design Decorator Pattern.
9/28/01F-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Design Patterns.
Lecture 16 Composition vs Inheritance: The Final Chapter.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
Decorator Pattern So many options!. Starbuzz Coffee  Want to offer a variety of combinations of coffee and condiments  Cost of a cup depends on the.
CSC 313 – Advanced Programming Topics. Open-Closed Principle Classes should be open for extension, but closed to modification  So, what does this mean?
CS 151: Object-Oriented Design October 24 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Decorator Explained. Intent Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to sub-classing for.
CSE 403 Lecture 14 Design Patterns. Today’s educational objective Understand the basics of design patterns Be able to distinguish them from design approaches.
Decorator Design Pattern Rick Mercer CSC 335: Object-Oriented Programming and Design.
November Ron McFadyen1 Composite Pattern A composite is a group of objects in which some objects contain others; one object may represent groups,
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IV Structural Patterns.
CS 210 Review October 3, 2006.
What if the milk price goes up? What if a new topping is added? What design principles are violated?
Bridge Bridge is used when we need to decouple an abstraction from its implementation so that the two can vary independently. This type of design pattern.
Decorator Design Pattern Rick Mercer CSC 335: Object-Oriented Programming and Design.
S.Ducasse Stéphane Ducasse 1 Decorator.
The Decorator Pattern (Structural) ©SoftMoore ConsultingSlide 1.
Decorator Design Pattern Phillip Shin. Overview Problem Solution Example Key points.
F-1 © 2007 T. Horton CS 4240 Principles of SW Design More design principles LSP, OCP, DIP, … And another pattern Decorator.
Whiteboardmaths.com © 2004 All rights reserved
CS 350 – Software Design The Decorator Pattern – Chapter 17 In this chapter we expand our e-commerce case study and learn how to use the Decorator Pattern.
Home – Mouse over text color Change the text color to #0dd53c when mouse over Same for Myanmar version.
Week 5, Class 3: Decorators Lab questions? Example: Starbuzz coffee Basic Pattern More examples Design Principles Compare with alternatives SE-2811 Slide.
Builder Introduction. Intent Separate the construction of a complex object from its representation so that the same construction process can create different.
Chapter 5 – System Modeling Lecture 1 1Chapter 5 System modeling.
CS 210 Introduction to Design Patterns September 14 th, 2006.
6.1b Adding And subtracting polynomials
Strategy: A Behavioral Design Pattern
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University
Decorator Intent Also known as Wrapper Example: a Text Window
Decorator Pattern Intent
Decorator Pattern.
BUTTERFLY EFFECT DIAGRAM
Object Oriented Design Patterns - Structural Patterns
OO Design Patterns - Decorator
Decorator Pattern Richard Gesick.
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.
Minidimension Example
Graphical User Interfaces in Java Event-driven programming
This diagram helps explains why angles at a point add to 360o.
Decorator Pattern.
Decorator Pattern The decorator pattern allows us to enclose an object inside another object. The enclosing object is called a decorator. The other object.
Presentation transcript:

Jan Ron McFadyen1 Decorator Sometimes we need a way to add responsibilities to an object dynamically and transparently. The Decorator pattern gives a mechanism without using inheritance … we can extend the capabilities of a class by adding subclasses with new methods or with different implementations of methods. The Decorator pattern allows one to add and remove layers to a base object.

Jan Ron McFadyen2 Decorator For example, we may have a text object and we want to sometimes add a scrollbar and sometimes we want to add a border. For example, we may have a text object and we want to sometimes add a vertical scrollbar and Sometimes we want to add a horizontal scrollbar. Original text object Scrollbar decorator Border decorator For example, we may have a text object and we want to sometimes add a vertical scrollbar and Sometimes we want to add a horizontal scrollbar.

Jan Ron McFadyen3 Decorator textScrollbarBorder decorators decorated The objects are linked like a linked list or chain of objects. The last in the list is the decorated object.

Jan Ron McFadyen4 Decorator 1 component decorator Concrete component Concrete decoratorA Concrete decoratorB operation() Client See page 91

Jan Ron McFadyen5 Decorator 1 component Beverage Condiment Decorator HouseBlend cost() getDescription getDescription() See page 92 DarkRoast Decaf cost() Espresso cost() MilkMochaSoyWhip cost() getDescription() cost() getDescription() cost() getDescription() cost() getDescription() The text shows an attribute in these concrete decorators – an implementation needs a reference to the next component Question: What is the object diagram for a whipped mocha decaf?

Jan Ron McFadyen6 Decorator Beverage Condiment Decorator HouseBlend DarkRoast Decaf Espresso MilkMochaSoyWhip Decorator Concrete decorator Concrete component Component Concrete decorator Concrete component The class diagram augmented to show the roles the classes/objects play in the decorator collaboration