Decorator Pattern Intent

Slides:



Advertisements
Similar presentations
Matt Klein. Decorator Pattern  Intent  Attach Additional responsibilities to an object by dynamically. Decorators provide a flexible alternative to.
Advertisements

AP 04/02 Structural Patterns Describe how classes and objects are composed to form larger structures Structural class patterns use inheritance to compose.
Decorator Pattern Lecture Oo29 Artificial Life Simulation.
1 Structural Design Patterns - Neeraj Ray. 2 Structural Patterns - Overview n Adapter n Bridge n Composite n Decorator.
02 - Structural Design Patterns – 1 Moshe Fresko Bar-Ilan University תשס"ח 2008.
DECORATOR by Ramani Natarajan Also known as ‘Wrapper.’ Also known as ‘Wrapper.’ According to ‘gang of four’(sounds like an Akira Kurosawa movie): A Decorator.
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
. Plab – Tirgul 12 Design Patterns. Design Patterns u The De-Facto Book on Design Patterns:
Decorator Josh Voils and Ralph Rodkey. GoF Definition of Intent Attach additional responsibilities to an object dynamically Provide an alternative to.
Design Patterns. CS351 - Software Engineering (AY2007)Slide 2 Behavioral patterns Suppose we have an aggregate data structure and we wish to access the.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
The Decorator Design Pattern (also known as the Wrapper) By Gordon Friedman Software Design and Documentation September 22, 2003.
Design Patterns 1 Design Patterns: Elements of Reusable Object – Oriented Software Course of Software Engineering II Serena Fabbri.
Winter 2011ACS-3913 Ron McFadyen1 Decorator Sometimes we need a way to add responsibilities to an object dynamically and transparently. The Decorator pattern.
Design Patterns.
Department of Computer Science, York University Object Oriented Software Construction 16/09/ :52 PM 0 COSC3311 – Software Design Decorator Pattern.
Structural Pattern: Decorator There are times when the use of subclasses to modify the behavior of individual objects is problematic. C h a p t e r 4.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
BUILDER, MEDIATOR, AND DECORATOR Team 2 (Eli.SE).
©Fraser Hutchinson & Cliff Green C++ Certificate Program C++ Intermediate Decorator, Strategy, State Patterns.
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.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IV Structural Patterns.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
Design Patterns: Elements of Reusable Object – Oriented Software Web Apps and Services.
1 Advanced Object-oriented Design – Principles and Patterns Structural Design Patterns.
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.
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.
Decorator Design Pattern Rick Mercer CSC 335: Object-Oriented Programming and Design.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
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.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
S.Ducasse Stéphane Ducasse 1 Adapter.
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.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns: MORE Examples
Abstract Factory Pattern
Chapter 10 Design Patterns.
Structural Patterns Structural patterns control the relationships between large portions of your applications. Structural patterns affect applications.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University
Factory Patterns 1.
Applying the Principles
Abstract Factory Pattern
Decorator Design Pattern
Intent (Thanks to Jim Fawcett for the slides)
More Design Patterns 1.
More Design Patterns 1.
Decorator Intent Also known as Wrapper Example: a Text Window
Design Pattern Detection
Jim Fawcett CSE776 – Design Patterns Summer 2003
Informatics 122 Software Design II
Object Oriented Design Patterns - Structural Patterns
Decorator Pattern Richard Gesick.
Behavioral Design Pattern
Structural Patterns: Adapter and Bridge
Strategy Design Pattern
Decorator.
Informatics 122 Software Design II
Decorator Pattern.
Adapter Pattern Jim Fawcett
Software Design Lecture 10.
Adapter Pattern Jim Fawcett
Presentation transcript:

Decorator Pattern Intent Attach additional responsibilities to an object dynamically. Provide a flexible alternative to subclassing for extending functionality

Decorator – Motivation Motivation – Applicability Need to add responsibility to individual objects not to entire classes Add properties like border, scrolling, etc to any user interface component as needed Enclose object within a decorator object for flexibility Nest recursively for unlimited customization

Decorator – Example Compose a border decorator with a scroll decorator for text view. a_border_decorator component a_scroll_decorator component a_text_view

Decorator – Example Diagram VISUAL_COMPONENT * draw * TEXT_VIEW + DECORATOR * draw component : VISUAL_ COMPONENT SCROLL_DECORATOR + BORDER_DECORATOR + draw scroll_position scroll_to draw border_width draw_border

Decorator – General Structure COMPONENT * method * CONCRETE_COMPONENT + DECORATOR * component : COMPONENT method CONCRETE_DECORATOR_ A + CONCRETE_DECORATOR_B + method other_feature method another_feature

Decorator – Implementation deferred class COMPONENT feature method is deferred end class CONCRETE_COMP feature method is... end deferred class DECORATOR feature component : COMPONENT end class CONCRETE_DECORATOR feature method is pre_actions component.method post_actions end Recursively do method for next in chain

Decorator – Applicability Add responsibilities to individual objects dynamically and transparently Without affecting other objects For responsibilities that can be withdrawn When subclass extension is impractical Sometimes a large number of independent extensions are possible Avoid combinatorial explosion Class definition may be hidden or otherwise unavailable for subclassing

Decorator – Participants Component Defines the interface for objects that can have responsibilities added to them dynamically Concrete component Defines an object to which additional responsibilities can be attached Decorator Maintains a reference to a component object and defines an interface that conforms to COMPONENT Concrete decorator Add responsibilities to the component

Decorator – Consequences Benefits More flexible than static inheritance Can add and remove responsibilities dynamically Can handle combinatorial explosion of possibilities Avoids feature laden classes high up in the hierarchy Pay as you go when adding responsibilities Can support unforeseen features Decorators are independent of the classes they decorate Functionality is composed in simple pieces

Decorator – Consequences – 2 Liabilities From object identity point of view, a decorated component is not identical Decorator acts as a transparent enclosure Cannot rely on object identity when using decorators Lots of little objects Often result in systems composed of many look alike objects Differ in the way they are interconnected, not in class or value of variables Can be difficult to learn and debug

Decorator – Related Patterns Adapter changes interface to an object, while Decorator changes an objects responsibilities Decorator is a degenerate Composite (only one component) Strategy lets you change the internals of an object, while Decorator changes the exterior