Decorator Pattern Richard Gesick.

Slides:



Advertisements
Similar presentations
Decorator Pattern Applied to I/O stream classes. Design Principle Classes should be open for extension, but closed for modification –Apply the principle.
Advertisements

Chapter 3: The Decorator Pattern
Matt Klein. Decorator Pattern  Intent  Attach Additional responsibilities to an object by dynamically. Decorators provide a flexible alternative to.
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.
SE-2811 Dr. Mark L. Hornick 1. The Decorator Pattern SE-2811 Dr. Mark L. Hornick 2.
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.
Interface & Abstract Class. Interface Definition All method in an interface are abstract methods. Methods are declared without the implementation part.
Design Patterns. CS351 - Software Engineering (AY2007)Slide 2 Behavioral patterns Suppose we have an aggregate data structure and we wish to access the.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Abstract Superclasses and Abstract Methods When.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
Prototype Creational Design Pattern By Brian Cavanaugh September 22, 2003 Software, Design and Documentation.
The Decorator Design Pattern (also known as the Wrapper) By Gordon Friedman Software Design and Documentation September 22, 2003.
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 2: Modelling.
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).
Session 21 Chapter 10: Mechanisms for Software Reuse.
Decorator Explained. Intent Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to sub-classing for.
CS 210 Adapter Pattern October 19 th, Adapters in real life Page 236 – Head First Design Patterns.
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
Structural Design Patterns
Week 6, Class 1 & 2: Decorators Return Exam Questions about lab due tomorrow in class? Threads Locking on null object invokeLater & the squares example.
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.
Incremental Design Why incremental design? Goal of incremental design Tools for incremental design  UML diagrams  Design principles  Design patterns.
Design Patterns -- Omkar. Introduction  When do we use design patterns  Uses of design patterns  Classification of design patterns  Creational design.
CSC 313 – Advanced Programming Topics. What Is the Factory Method?  Creation details hidden by AbstractCreator  Does effective job of limiting concrete.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
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.
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.
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.
The Decorator Pattern Decorators in Java I/O classes SE-2811 Dr. Mark L. Hornick 1.
CSCI 383 Object-Oriented Programming & Design Lecture 15 Martin van Bommel.
Design Patterns: MORE Examples
Sections Inheritance and Abstract Classes
Chapter 1: Introduction to Systems Analysis and Design
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University
Factory Patterns 1.
Behavioral Design Patterns
Observer Design Pattern
More Design Patterns 1.
More Design Patterns 1.
7. Decorator, Façade Patterns
Decorator Intent Also known as Wrapper Example: a Text Window
Decorator Pattern Intent
lecture 08, OO Design Principle
Informatics 122 Software Design II
Object Oriented Design Patterns - Structural Patterns
OO Design Patterns - Decorator
Software Design Lecture : 14.
Structural Patterns: Adapter and Bridge
7. Decorator SE2811 Software Component Design
Design Patterns Imran Rashid CTO at ManiWeber Technologies.
11. MVC SE2811 Software Component Design
11. MVC SE2811 Software Component Design
Decorator Pattern.
Chapter 1: Introduction to Systems Analysis and Design
Software Design Lecture 10.
Presentation transcript:

Decorator Pattern Richard Gesick

Pattern Overview The Decorator pattern provides a flexible alternative to subclassing by attaching additional responsibilities to an object dynamically, by using an instance of a subclass of the original class that delegates operations to the original object This pattern type falls into the Structural Patterns category and deals with objects.

Structure -- UML Construction The ConcreteComponent is the object that can be decorated An instance variable is included in the ConcreteDecorator for the object that it will decorate.

As seen in the diagram each component can be used on its own or wrapped by a decorator.  Decorators extend the state of the component.  Additionally they implement the same interface or abstract class as the component they are going to decorate

Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extended functionality.

Applicability Need to add responsibilities to objects dynamically and transparently Need to withdraw responsibilities Need to support large combinations of responsibilities without a class explosion When extension by subclassing is impractical or impossible

Consequences More flexible than static inheritance Avoids feature-laden classes high up in the hierarchy A decorator and its component aren't identical Decorators can be an effective, less-confusing and more easily maintainable substitute for multiple-inheritance.

Lots of little objects! Functionality of a class can be extended knowing only its interface; source is not always required.  Therefore, the class is closed to modification, but open to extension. Decorators allow more flexibility to code by avoiding extending your class hierarchy just to support a characteristic. Resources are used as they are needed since run-time objects are created.

The Open-Closed Principle Design Principle: Classes should be open for extension, but closed for modification.  Our goal is to allow classes to be easily extended to incorporate new behavior without modifying existing code.

This gives us designs that are resilient to change and flexible enough to take on new functionality to meet changing requirements.  Be careful when choosing the areas of code that need to be extended; applying the Open-Closed Principle EVERYWHERE is wasteful, unnecessary, and can lead to complex, hard to understand code.