SlideShare a Scribd company logo
Decorator Design
Pattern
Elements of Reusable Object-Oriented Software
Content
1. Design Patterns
2. Decorator Design Pattern
3. Example
I. Class Structure
II. Implementation
4. Conclusion
2
Design Pattern
3
Best practices Solutions to
general problems
Decorator Design Pattern
• Attach additional responsibilities to an object dynamically.
• Decorators provide a flexible alternative to subclassing for
extending functionality.
• Wrapping a gift, putting it in a box, and wrapping the box.
4
Problem
You want to add behavior or state to individual objects at runtime.
Inheritance is not feasible because it is static and applies to an
entire class.
5
Example
6
Window
Window with Vertical
Scrollbar
Window with Horizontal
Scrollbar
Window with Border
Window with Vertical and Horizontal Scrollbar
Window with Vertical and Horizontal Scrollbar and Border
Class Structure
7
<<interface>>
Window
+ draw()
<<class>>
MainWindow
+ draw()
<<interface>>
WindowDecorator
+ draw()
<<class>>
Border
<<class>>
Vertical SB
<<class>>
Horizontal SB
Implementation
8
Window appMainWindow = new BorderDecorator(
new HorizontalScrollBarDecorator(
new VerticalScrollBarDecorator(
new MainWindow( 80, 24 ))));
appMainWindow.draw();
Conclusion
• Decorators allow behavior modification at runtime rather than
going back into existing code and making changes
• The decorator pattern supports the principle that classes should
be open for extension but closed for modification
9
Kanushka Gayan
SE intern @ Extrogene Software (Pvt) Ltd
kanushkanet@gmail.com
071 879 4546
Thank You!

More Related Content

PPTX
Design Pattern(decorator design pattern) and anti pattern
PPTX
Decorator Pattern
PPTX
Decorator design pattern
PPTX
Decorator Pattern presentation theory and examples
PPTX
Design pattern reading group – decorator pattern
PPTX
Decorator Pattern 2.pptxdsadsadsadsadasdasdsa
PPT
Design patterns represent the best practices used by experienced object-orien...
PPT
10-DesignPatterns.ppt
Design Pattern(decorator design pattern) and anti pattern
Decorator Pattern
Decorator design pattern
Decorator Pattern presentation theory and examples
Design pattern reading group – decorator pattern
Decorator Pattern 2.pptxdsadsadsadsadasdasdsa
Design patterns represent the best practices used by experienced object-orien...
10-DesignPatterns.ppt

Similar to Decorator Design Pattern (20)

PPTX
java training in chennai
PDF
Decorator & Presenter Design Pattern
PPTX
Design Patterns - 01 Introduction and Decorator Pattern
PPTX
Decorator design pattern
ZIP
Decorator pattern
PDF
Design patterns 1july
PDF
Webinar on Design Patterns titled 'Dive into Design Patterns'
PDF
Design Patterns : The Ultimate Blueprint for Software
PPT
Phani Kumar - Decorator Pattern
PPTX
Decorator pattern
PPTX
Design patterns
PDF
Applying Design Principles in Practice
PDF
Applying Design Principles in Practice - ISEC 2015 Tutorial
PPT
Stoop 439-decorator
PPT
Design patterns structuralpatterns(thedecoratorpattern)
 
PDF
Decorator Pattern | Object Oriented Design Pattern
PDF
Software Architecture: Principles, Patterns and Practices
PDF
Design patterns in XPages
PDF
Three ways to apply design principles in practice
java training in chennai
Decorator & Presenter Design Pattern
Design Patterns - 01 Introduction and Decorator Pattern
Decorator design pattern
Decorator pattern
Design patterns 1july
Webinar on Design Patterns titled 'Dive into Design Patterns'
Design Patterns : The Ultimate Blueprint for Software
Phani Kumar - Decorator Pattern
Decorator pattern
Design patterns
Applying Design Principles in Practice
Applying Design Principles in Practice - ISEC 2015 Tutorial
Stoop 439-decorator
Design patterns structuralpatterns(thedecoratorpattern)
 
Decorator Pattern | Object Oriented Design Pattern
Software Architecture: Principles, Patterns and Practices
Design patterns in XPages
Three ways to apply design principles in practice
Ad

More from Kanushka Gayan (6)

PPTX
Progressive Web Apps
PPTX
Microservices Architecture
PPTX
Slim 3 PHP micro framework
PPTX
REST API
PPTX
Factory Design Pattern
Progressive Web Apps
Microservices Architecture
Slim 3 PHP micro framework
REST API
Factory Design Pattern
Ad

Recently uploaded (20)

PPTX
Introduction to Building Materials
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PDF
advance database management system book.pdf
PPTX
Digestion and Absorption of Carbohydrates, Proteina and Fats
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PPTX
Lesson notes of climatology university.
PDF
IGGE1 Understanding the Self1234567891011
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
Classroom Observation Tools for Teachers
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
Indian roads congress 037 - 2012 Flexible pavement
PDF
Complications of Minimal Access Surgery at WLH
Introduction to Building Materials
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
UNIT III MENTAL HEALTH NURSING ASSESSMENT
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
advance database management system book.pdf
Digestion and Absorption of Carbohydrates, Proteina and Fats
A systematic review of self-coping strategies used by university students to ...
Paper A Mock Exam 9_ Attempt review.pdf.
Practical Manual AGRO-233 Principles and Practices of Natural Farming
Lesson notes of climatology university.
IGGE1 Understanding the Self1234567891011
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Classroom Observation Tools for Teachers
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
Indian roads congress 037 - 2012 Flexible pavement
Complications of Minimal Access Surgery at WLH

Decorator Design Pattern

Editor's Notes

  • #2: https://sourcemaking.com/design_patterns/decorator
  • #5: Decorator pattern allows a user to add new functionality to an existing object without altering its structure. This type of design pattern comes under structural pattern as this pattern acts as a wrapper to existing class. This pattern creates a decorator class which wraps the original class and provides additional functionality keeping class methods signature intact.
  • #7: Suppose you are working on a user interface toolkit and you wish to support adding borders and scroll bars to windows. You could define an inheritance hierarchy like But the Decorator pattern suggests giving the client the ability to specify whatever combination of "features" is desired.
  • #8: Suppose you are working on a user interface toolkit and you wish to support adding borders and scroll bars to windows. You could define an inheritance hierarchy like But the Decorator pattern suggests giving the client the ability to specify whatever combination of "features" is desired.