![Page 1: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original](https://reader034.vdocuments.net/reader034/viewer/2022051811/601d7d67e3da425fbc5d2b33/html5/thumbnails/1.jpg)
PRESENTATION ON DECORATOR PATTERN
By RAHUL TAWADE
![Page 2: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original](https://reader034.vdocuments.net/reader034/viewer/2022051811/601d7d67e3da425fbc5d2b33/html5/thumbnails/2.jpg)
CONTENTS
Introduction
Decorator Pattern
Class Diagrams
General Scenario
Examples of Design pattern
Code Demonstration
Where used in Java
Reference
![Page 3: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original](https://reader034.vdocuments.net/reader034/viewer/2022051811/601d7d67e3da425fbc5d2b33/html5/thumbnails/3.jpg)
INTRODUCTION
DESIGN PATTERN
What is Design Pattern?
“In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.”
Simple words: A design pattern is just a way to design the solutionfor a particular problem.
These solutions were obtained by trial and error by software developers over quite a substantial periodof time.
GANG OF FOUR(GOF) ???
![Page 4: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original](https://reader034.vdocuments.net/reader034/viewer/2022051811/601d7d67e3da425fbc5d2b33/html5/thumbnails/4.jpg)
INTRO CONT..
What is Gang of Four (GOF)? In 1994, four authors Erich Gamma, Richard Helm, Ralph Johnson and John
Vlissides published a book titled Design Patterns - Elements of Reusable Object-Oriented Software
These authors are collectively known as Gang of Four (GOF).
Types of Design Patterns :
1) Creational Patterns : These design patterns provide a way to create objects while hiding the
creation logic
2) Structural Patterns : These design patterns concern class and object composition
3) Behavioural Patterns : These design patterns are specifically concerned with communication
between objects.
4) J2EE Patterns : These patterns are identified by Sun Java Center.
![Page 5: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original](https://reader034.vdocuments.net/reader034/viewer/2022051811/601d7d67e3da425fbc5d2b33/html5/thumbnails/5.jpg)
DECORATOR PATTERN
Structural Pattern
The Decorator Pattern attaches additional responsibilities to an object dynamically.
This pattern creates a decorator class which wraps the original class and provides additional functionality
Steps :1. Create an interface.2. Create concrete classes implementing the same interface.3. Create abstract Decorator class implementing the interface.4. Create concrete decorator class extending the abstract Decorator class.5. Use the concrete Decorator to decorate objects.
![Page 6: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original](https://reader034.vdocuments.net/reader034/viewer/2022051811/601d7d67e3da425fbc5d2b33/html5/thumbnails/6.jpg)
Class diagram
![Page 7: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original](https://reader034.vdocuments.net/reader034/viewer/2022051811/601d7d67e3da425fbc5d2b33/html5/thumbnails/7.jpg)
General Scenarios
![Page 8: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original](https://reader034.vdocuments.net/reader034/viewer/2022051811/601d7d67e3da425fbc5d2b33/html5/thumbnails/8.jpg)
General Scenarios Cont…
![Page 9: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original](https://reader034.vdocuments.net/reader034/viewer/2022051811/601d7d67e3da425fbc5d2b33/html5/thumbnails/9.jpg)
Coffee Shop Scenario
![Page 10: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original](https://reader034.vdocuments.net/reader034/viewer/2022051811/601d7d67e3da425fbc5d2b33/html5/thumbnails/10.jpg)
Coffee Shop using Decorator:
Fig: Class Diagram
![Page 11: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original](https://reader034.vdocuments.net/reader034/viewer/2022051811/601d7d67e3da425fbc5d2b33/html5/thumbnails/11.jpg)
Code
Interface :
![Page 12: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original](https://reader034.vdocuments.net/reader034/viewer/2022051811/601d7d67e3da425fbc5d2b33/html5/thumbnails/12.jpg)
Code
Concrete Class :
![Page 13: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original](https://reader034.vdocuments.net/reader034/viewer/2022051811/601d7d67e3da425fbc5d2b33/html5/thumbnails/13.jpg)
Code
Abstract Decorator class
![Page 14: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original](https://reader034.vdocuments.net/reader034/viewer/2022051811/601d7d67e3da425fbc5d2b33/html5/thumbnails/14.jpg)
Code
Concrete Decorator
![Page 15: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original](https://reader034.vdocuments.net/reader034/viewer/2022051811/601d7d67e3da425fbc5d2b33/html5/thumbnails/15.jpg)
Code
Test class
![Page 16: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original](https://reader034.vdocuments.net/reader034/viewer/2022051811/601d7d67e3da425fbc5d2b33/html5/thumbnails/16.jpg)
Output
![Page 17: PRESENTATION ON DECORATOR PATTERN · The Decorator Pattern attaches additional responsibilities to an object dynamically. This pattern creates a decorator class which wraps the original](https://reader034.vdocuments.net/reader034/viewer/2022051811/601d7d67e3da425fbc5d2b33/html5/thumbnails/17.jpg)
Decorator Pattern Used in Java