SlideShare a Scribd company logo
• Click to edit Master text styles
– Second level
• Third level
– Fourth level
» Fifth level
Decorator Pattern
Adeel Riaz
Muhammad Shehyyar
Muhammad Owais
Sara Rehmatullah
Ayesha Mehfooz
Advisor: Muhammad Qasim Pasta
PAF KIET Fall 11PAF-KIET CoCIS Dept.
• Click to edit Master text styles
– Second level
• Third level
– Fourth level
» Fifth level
Concept of Decorating in Real World
Before Decorating
After Decorating
PAF-KIET CoCIS Dept.
• Click to edit Master text styles
– Second level
• Third level
– Fourth level
» Fifth level
Problem??
PAF-KIET CoCIS Dept.
• Click to edit Master text styles
– Second level
• Third level
– Fourth level
» Fifth level
Decorator Pattern Approach
PAF-KIET CoCIS Dept.
• Click to edit Master text styles
– Second level
• Third level
– Fourth level
» Fifth level
Problem??
PAF-KIET CoCIS Dept.
Whenever a team member becomes a team lead, we have to create a new
object of team lead and the previous object that points to that employee (team
member) may be destroyed.
Another case is when an employee can perform responsibilities of a team member as well as those of a team
lead or a manager can perform team leads responsibilities. In that case you need to create two objects for the
same employee which is totally wrong.
• Click to edit Master text styles
– Second level
• Third level
– Fourth level
» Fifth level
Decorator Pattern Approach
PAF-KIET CoCIS Dept.
Now, if we want to change responsibilities of an employee to manager we just need a new
Manager (Decorator) and assigning that employee to it will solve our problem. Same is the case
when a team lead’s responsibilities are revoked, and some other member becomes team lead,
we just need to swap employee objects within TeamMember and TeamLead decorators.
• Click to edit Master text styles
– Second level
• Third level
– Fourth level
» Fifth level
Intent
The Decorator Pattern attaches additional
responsibilities to an object dynamically.
Decorators provide a flexible alternative to
Sub-classing for extending functionality.
PAF-KIET CoCIS Dept.
• Click to edit Master text styles
– Second level
• Third level
– Fourth level
» Fifth level
Motivation
• Sometimes we want to add responsibilities to individual
objects not to an entire class.
• Inheriting responsibilities from another class attaches
them to every subclass instance statically. This is
inflexible.
PAF-KIET CoCIS Dept.
• Click to edit Master text styles
– Second level
• Third level
– Fourth level
» Fifth level
Graphical user interface toolkit
PAF-KIET CoCIS Dept.
• Click to edit Master text styles
– Second level
• Third level
– Fourth level
» Fifth level
Structure
PAF-KIET CoCIS Dept.
• Click to edit Master text styles
– Second level
• Third level
– Fourth level
» Fifth level
Example
PAF-KIET CoCIS Dept.
• Click to edit Master text styles
– Second level
• Third level
– Fourth level
» Fifth level
Applicability
PAF-KIET CoCIS Dept.
•To add responsibilities to individual objects dynamically
and transparently, that is, without affecting other objects.
•For responsibilities that can be withdrawn.
•When extension by sub-classing is impractical.
Sometimes a large number of independent extensions
are possible and would produce an explosion of
subclasses to support every combination. Or a class
definition may be hidden or otherwise unavailable for
sub-classing.
• Click to edit Master text styles
– Second level
• Third level
– Fourth level
» Fifth level
Participants
• Component (VisualComponent)
defines the interface for objects that can have responsibilities added
to them dynamically.
• ConcreteComponent (TextView)
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‘s interface.
• ConcreteDecorator (BorderDecorator, ScrollDecorator)
adds responsibilities to the component.
PAF-KIET CoCIS Dept.
• Click to edit Master text styles
– Second level
• Third level
– Fourth level
» Fifth level
Participants
PAF-KIET CoCIS Dept.
• Click to edit Master text styles
– Second level
• Third level
– Fourth level
» Fifth level
Collaborations
PAF-KIET CoCIS Dept.
•Decorator forwards requests to its Component object. It may
optionally perform additional operations before and after forwarding
the request.
• Click to edit Master text styles
– Second level
• Third level
– Fourth level
» Fifth level
Consequences
• More flexible than static inheritance.
• Avoids feature laden classes high up in
hierarchy.
• Lots of little objects that look alike. So it is
hard to learn and debug.
• A decorator and its components are not
identical. So checking object identification can
cause problems.
PAF-KIET CoCIS Dept.
• Click to edit Master text styles
– Second level
• Third level
– Fourth level
» Fifth level
Implementation
Several issues should be considered when applying the Decorator pattern:
1. Interface conformance:
A decorator object’s interface must conform to the interface of the
component it decorates.
2. Omitting the abstract Decorator class:
If only one responsibility is needed, don’t define abstract Decorator.
Merge Decorator’s responsibility into the ConcreteDecorator.
3. Keeping Component classes light weight:
Component class should be dedicated to defining an interface, no other
functions. Keep it light and simple. A complex Component class might make
Decorator too costly to use in quantity.
4. Changing the skin of an object versus its guts:
Decorator classes should act as a layer of skin over an object. If there’s a need
to change the object’s guts, use Strategy pattern.
PAF-KIET CoCIS Dept.
• Click to edit Master text styles
– Second level
• Third level
– Fourth level
» Fifth level
Builder VS Decorator
PAF-KIET CoCIS Dept.
• Click to edit Master text styles
– Second level
• Third level
– Fourth level
» Fifth level
PAF-KIET CoCIS Dept.
Builder VS Decorator
• Click to edit Master text styles
– Second level
• Third level
– Fourth level
» Fifth level
Related Patterns
PAF-KIET CoCIS Dept.
•Adapter: A decorator is different from an adapter in that a
decorator only changes an object‘s responsibilities, not its
interface; an adapter will give an object a completely new
interface.
•Strategy : A decorator lets you change the skin of an object; a
strategy lets you change the guts. These are two alternative
ways of changing an object.

More Related Content

What's hot

CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT
CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPTCS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT
CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT
leela rani
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
Salem-Kabbani
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
Anjan Kumar Bollam
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
naveen kumar
 
Bridge pattern
Bridge patternBridge pattern
Bridge pattern
Shakil Ahmed
 
Uml class diagram and packages ppt for dot net
Uml class diagram and packages ppt for dot netUml class diagram and packages ppt for dot net
Uml class diagram and packages ppt for dot net
mekhap
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
Satheesh Sukumaran
 
Adapter pattern
Adapter patternAdapter pattern
Adapter pattern
Shakil Ahmed
 
Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan Gole
Chetan Gole
 
Bridge Design Pattern
Bridge Design PatternBridge Design Pattern
Bridge Design Pattern
Shahriar Hyder
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
Jyaasa Technologies
 
Design pattern-presentation
Design pattern-presentationDesign pattern-presentation
Design pattern-presentation
Rana Muhammad Asif
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patterns
Amit Kabra
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
soms_1
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
Sanae BEKKAR
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
Shakil Ahmed
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
Anuja Arosha
 
Facade Design Pattern
Facade Design PatternFacade Design Pattern
Facade Design Pattern
Livares Technologies Pvt Ltd
 
Class diagrams
Class diagramsClass diagrams
Class diagrams
Nadia_Nazeer
 
Adapter Pattern
Adapter PatternAdapter Pattern
Adapter Pattern
AgilanVageesan
 

What's hot (20)

CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT
CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPTCS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT
CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
 
Bridge pattern
Bridge patternBridge pattern
Bridge pattern
 
Uml class diagram and packages ppt for dot net
Uml class diagram and packages ppt for dot netUml class diagram and packages ppt for dot net
Uml class diagram and packages ppt for dot net
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Adapter pattern
Adapter patternAdapter pattern
Adapter pattern
 
Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan Gole
 
Bridge Design Pattern
Bridge Design PatternBridge Design Pattern
Bridge Design Pattern
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
 
Design pattern-presentation
Design pattern-presentationDesign pattern-presentation
Design pattern-presentation
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patterns
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Facade Design Pattern
Facade Design PatternFacade Design Pattern
Facade Design Pattern
 
Class diagrams
Class diagramsClass diagrams
Class diagrams
 
Adapter Pattern
Adapter PatternAdapter Pattern
Adapter Pattern
 

Similar to Decorator Design Pattern

Link-Link MATERI TRAINING "Strategic Sourcing & VENDOR MANAGEMENT"
Link-Link MATERI TRAINING "Strategic Sourcing & VENDOR MANAGEMENT"Link-Link MATERI TRAINING "Strategic Sourcing & VENDOR MANAGEMENT"
Link-Link MATERI TRAINING "Strategic Sourcing & VENDOR MANAGEMENT"
Kanaidi ken
 
Geek Sync | Database People and DevOps: The Fundamentals
Geek Sync | Database People and DevOps: The FundamentalsGeek Sync | Database People and DevOps: The Fundamentals
Geek Sync | Database People and DevOps: The Fundamentals
IDERA Software
 
7 ways of reducing tpm cost
7 ways of reducing tpm cost 7 ways of reducing tpm cost
7 ways of reducing tpm cost
TradeInsight
 
Bootstrap - KNOWARTH
Bootstrap - KNOWARTHBootstrap - KNOWARTH
Bootstrap - KNOWARTH
KNOWARTH Technologies
 
Maintenance & Re-Engineering of Software
Maintenance & Re-Engineering of SoftwareMaintenance & Re-Engineering of Software
Maintenance & Re-Engineering of Software
Adeel Riaz
 
MongoDB and MongoMK Source Event
MongoDB and MongoMK Source EventMongoDB and MongoMK Source Event
MongoDB and MongoMK Source Event
Yuval Ararat
 
Information Audit and Card Sorting Exercise in One
Information Audit and Card Sorting Exercise in OneInformation Audit and Card Sorting Exercise in One
Information Audit and Card Sorting Exercise in One
Sarah Burns
 
Winning Strategies for a Successful ERP Implementation
Winning Strategies for a Successful ERP ImplementationWinning Strategies for a Successful ERP Implementation
Winning Strategies for a Successful ERP Implementation
Jonathan Gross
 
What to do when things go wrong with Drupal
What to do when things go wrong with DrupalWhat to do when things go wrong with Drupal
What to do when things go wrong with Drupal
DrupalcampAtlanta2012
 
Agena agent based modeling-AdSiF
Agena   agent based modeling-AdSiFAgena   agent based modeling-AdSiF
Agena agent based modeling-AdSiF
Mehmet Fatih Hocaoglu
 
Bypassing malware detection mechanisms in online banking
Bypassing malware detection mechanisms in online bankingBypassing malware detection mechanisms in online banking
Bypassing malware detection mechanisms in online banking
Jakub Kałużny
 
ALOA conceptual model: Aligning Learning Outcomes and Assessment
ALOA conceptual model: Aligning Learning Outcomes and AssessmentALOA conceptual model: Aligning Learning Outcomes and Assessment
ALOA conceptual model: Aligning Learning Outcomes and Assessment
Rita Falcão de Berredo
 
Link-link MATERI Training "MANAJEMEN KASIR INOVATIF"
Link-link MATERI Training "MANAJEMEN KASIR INOVATIF"Link-link MATERI Training "MANAJEMEN KASIR INOVATIF"
Link-link MATERI Training "MANAJEMEN KASIR INOVATIF"
Kanaidi ken
 
DiscoveringDH_ManagingDigitalProjects
DiscoveringDH_ManagingDigitalProjectsDiscoveringDH_ManagingDigitalProjects
DiscoveringDH_ManagingDigitalProjects
Florida State University
 
PELAKSANAAN + Link-link MATERI Training "MANAJEMEN KASIR Inovatif"
PELAKSANAAN + Link-link MATERI Training "MANAJEMEN KASIR Inovatif"PELAKSANAAN + Link-link MATERI Training "MANAJEMEN KASIR Inovatif"
PELAKSANAAN + Link-link MATERI Training "MANAJEMEN KASIR Inovatif"
Kanaidi ken
 
Content Marketing and the Digital Dinosaurs
Content Marketing and the Digital DinosaursContent Marketing and the Digital Dinosaurs
Content Marketing and the Digital Dinosaurs
Frances Deighton
 
Creating Layouts and Landing Pages for Drupal 8 - DrupalCon Dublin
Creating Layouts and Landing Pages for Drupal 8 - DrupalCon DublinCreating Layouts and Landing Pages for Drupal 8 - DrupalCon Dublin
Creating Layouts and Landing Pages for Drupal 8 - DrupalCon Dublin
Suzanne Dergacheva
 
Few minutes To better Code - Refactoring
Few minutes To better Code - RefactoringFew minutes To better Code - Refactoring
Few minutes To better Code - Refactoring
Diaa Al-Salehi
 
Well Planned is Half Done: Planning Projects in the Digitization World
Well Planned is Half Done: Planning Projects in the Digitization WorldWell Planned is Half Done: Planning Projects in the Digitization World
Well Planned is Half Done: Planning Projects in the Digitization World
Florida State University
 
Enterprise DevOps
Enterprise DevOpsEnterprise DevOps
Enterprise DevOps
Vistara
 

Similar to Decorator Design Pattern (20)

Link-Link MATERI TRAINING "Strategic Sourcing & VENDOR MANAGEMENT"
Link-Link MATERI TRAINING "Strategic Sourcing & VENDOR MANAGEMENT"Link-Link MATERI TRAINING "Strategic Sourcing & VENDOR MANAGEMENT"
Link-Link MATERI TRAINING "Strategic Sourcing & VENDOR MANAGEMENT"
 
Geek Sync | Database People and DevOps: The Fundamentals
Geek Sync | Database People and DevOps: The FundamentalsGeek Sync | Database People and DevOps: The Fundamentals
Geek Sync | Database People and DevOps: The Fundamentals
 
7 ways of reducing tpm cost
7 ways of reducing tpm cost 7 ways of reducing tpm cost
7 ways of reducing tpm cost
 
Bootstrap - KNOWARTH
Bootstrap - KNOWARTHBootstrap - KNOWARTH
Bootstrap - KNOWARTH
 
Maintenance & Re-Engineering of Software
Maintenance & Re-Engineering of SoftwareMaintenance & Re-Engineering of Software
Maintenance & Re-Engineering of Software
 
MongoDB and MongoMK Source Event
MongoDB and MongoMK Source EventMongoDB and MongoMK Source Event
MongoDB and MongoMK Source Event
 
Information Audit and Card Sorting Exercise in One
Information Audit and Card Sorting Exercise in OneInformation Audit and Card Sorting Exercise in One
Information Audit and Card Sorting Exercise in One
 
Winning Strategies for a Successful ERP Implementation
Winning Strategies for a Successful ERP ImplementationWinning Strategies for a Successful ERP Implementation
Winning Strategies for a Successful ERP Implementation
 
What to do when things go wrong with Drupal
What to do when things go wrong with DrupalWhat to do when things go wrong with Drupal
What to do when things go wrong with Drupal
 
Agena agent based modeling-AdSiF
Agena   agent based modeling-AdSiFAgena   agent based modeling-AdSiF
Agena agent based modeling-AdSiF
 
Bypassing malware detection mechanisms in online banking
Bypassing malware detection mechanisms in online bankingBypassing malware detection mechanisms in online banking
Bypassing malware detection mechanisms in online banking
 
ALOA conceptual model: Aligning Learning Outcomes and Assessment
ALOA conceptual model: Aligning Learning Outcomes and AssessmentALOA conceptual model: Aligning Learning Outcomes and Assessment
ALOA conceptual model: Aligning Learning Outcomes and Assessment
 
Link-link MATERI Training "MANAJEMEN KASIR INOVATIF"
Link-link MATERI Training "MANAJEMEN KASIR INOVATIF"Link-link MATERI Training "MANAJEMEN KASIR INOVATIF"
Link-link MATERI Training "MANAJEMEN KASIR INOVATIF"
 
DiscoveringDH_ManagingDigitalProjects
DiscoveringDH_ManagingDigitalProjectsDiscoveringDH_ManagingDigitalProjects
DiscoveringDH_ManagingDigitalProjects
 
PELAKSANAAN + Link-link MATERI Training "MANAJEMEN KASIR Inovatif"
PELAKSANAAN + Link-link MATERI Training "MANAJEMEN KASIR Inovatif"PELAKSANAAN + Link-link MATERI Training "MANAJEMEN KASIR Inovatif"
PELAKSANAAN + Link-link MATERI Training "MANAJEMEN KASIR Inovatif"
 
Content Marketing and the Digital Dinosaurs
Content Marketing and the Digital DinosaursContent Marketing and the Digital Dinosaurs
Content Marketing and the Digital Dinosaurs
 
Creating Layouts and Landing Pages for Drupal 8 - DrupalCon Dublin
Creating Layouts and Landing Pages for Drupal 8 - DrupalCon DublinCreating Layouts and Landing Pages for Drupal 8 - DrupalCon Dublin
Creating Layouts and Landing Pages for Drupal 8 - DrupalCon Dublin
 
Few minutes To better Code - Refactoring
Few minutes To better Code - RefactoringFew minutes To better Code - Refactoring
Few minutes To better Code - Refactoring
 
Well Planned is Half Done: Planning Projects in the Digitization World
Well Planned is Half Done: Planning Projects in the Digitization WorldWell Planned is Half Done: Planning Projects in the Digitization World
Well Planned is Half Done: Planning Projects in the Digitization World
 
Enterprise DevOps
Enterprise DevOpsEnterprise DevOps
Enterprise DevOps
 

Recently uploaded

Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
Orca: Nocode Graphical Editor for Container Orchestration
Orca: Nocode Graphical Editor for Container OrchestrationOrca: Nocode Graphical Editor for Container Orchestration
Orca: Nocode Graphical Editor for Container Orchestration
Pedro J. Molina
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 
ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.
Maitrey Patel
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
sjcobrien
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
Bert Jan Schrijver
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
dakas1
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
kalichargn70th171
 
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdfThe Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
kalichargn70th171
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
Reetu63
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
safelyiotech
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
Marcin Chrost
 
Manyata Tech Park Bangalore_ Infrastructure, Facilities and More
Manyata Tech Park Bangalore_ Infrastructure, Facilities and MoreManyata Tech Park Bangalore_ Infrastructure, Facilities and More
Manyata Tech Park Bangalore_ Infrastructure, Facilities and More
narinav14
 
DevOps Consulting Company | Hire DevOps Services
DevOps Consulting Company | Hire DevOps ServicesDevOps Consulting Company | Hire DevOps Services
DevOps Consulting Company | Hire DevOps Services
seospiralmantra
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
ervikas4
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
Tier1 app
 
TMU毕业证书精仿办理
TMU毕业证书精仿办理TMU毕业证书精仿办理
TMU毕业证书精仿办理
aeeva
 

Recently uploaded (20)

Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
Orca: Nocode Graphical Editor for Container Orchestration
Orca: Nocode Graphical Editor for Container OrchestrationOrca: Nocode Graphical Editor for Container Orchestration
Orca: Nocode Graphical Editor for Container Orchestration
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 
ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
 
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdfThe Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
 
Manyata Tech Park Bangalore_ Infrastructure, Facilities and More
Manyata Tech Park Bangalore_ Infrastructure, Facilities and MoreManyata Tech Park Bangalore_ Infrastructure, Facilities and More
Manyata Tech Park Bangalore_ Infrastructure, Facilities and More
 
DevOps Consulting Company | Hire DevOps Services
DevOps Consulting Company | Hire DevOps ServicesDevOps Consulting Company | Hire DevOps Services
DevOps Consulting Company | Hire DevOps Services
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
 
TMU毕业证书精仿办理
TMU毕业证书精仿办理TMU毕业证书精仿办理
TMU毕业证书精仿办理
 

Decorator Design Pattern

  • 1. • Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level Decorator Pattern Adeel Riaz Muhammad Shehyyar Muhammad Owais Sara Rehmatullah Ayesha Mehfooz Advisor: Muhammad Qasim Pasta PAF KIET Fall 11PAF-KIET CoCIS Dept.
  • 2. • Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level Concept of Decorating in Real World Before Decorating After Decorating PAF-KIET CoCIS Dept.
  • 3. • Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level Problem?? PAF-KIET CoCIS Dept.
  • 4. • Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level Decorator Pattern Approach PAF-KIET CoCIS Dept.
  • 5. • Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level Problem?? PAF-KIET CoCIS Dept. Whenever a team member becomes a team lead, we have to create a new object of team lead and the previous object that points to that employee (team member) may be destroyed. Another case is when an employee can perform responsibilities of a team member as well as those of a team lead or a manager can perform team leads responsibilities. In that case you need to create two objects for the same employee which is totally wrong.
  • 6. • Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level Decorator Pattern Approach PAF-KIET CoCIS Dept. Now, if we want to change responsibilities of an employee to manager we just need a new Manager (Decorator) and assigning that employee to it will solve our problem. Same is the case when a team lead’s responsibilities are revoked, and some other member becomes team lead, we just need to swap employee objects within TeamMember and TeamLead decorators.
  • 7. • Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level Intent The Decorator Pattern attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to Sub-classing for extending functionality. PAF-KIET CoCIS Dept.
  • 8. • Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level Motivation • Sometimes we want to add responsibilities to individual objects not to an entire class. • Inheriting responsibilities from another class attaches them to every subclass instance statically. This is inflexible. PAF-KIET CoCIS Dept.
  • 9. • Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level Graphical user interface toolkit PAF-KIET CoCIS Dept.
  • 10. • Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level Structure PAF-KIET CoCIS Dept.
  • 11. • Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level Example PAF-KIET CoCIS Dept.
  • 12. • Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level Applicability PAF-KIET CoCIS Dept. •To add responsibilities to individual objects dynamically and transparently, that is, without affecting other objects. •For responsibilities that can be withdrawn. •When extension by sub-classing is impractical. Sometimes a large number of independent extensions are possible and would produce an explosion of subclasses to support every combination. Or a class definition may be hidden or otherwise unavailable for sub-classing.
  • 13. • Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level Participants • Component (VisualComponent) defines the interface for objects that can have responsibilities added to them dynamically. • ConcreteComponent (TextView) 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‘s interface. • ConcreteDecorator (BorderDecorator, ScrollDecorator) adds responsibilities to the component. PAF-KIET CoCIS Dept.
  • 14. • Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level Participants PAF-KIET CoCIS Dept.
  • 15. • Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level Collaborations PAF-KIET CoCIS Dept. •Decorator forwards requests to its Component object. It may optionally perform additional operations before and after forwarding the request.
  • 16. • Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level Consequences • More flexible than static inheritance. • Avoids feature laden classes high up in hierarchy. • Lots of little objects that look alike. So it is hard to learn and debug. • A decorator and its components are not identical. So checking object identification can cause problems. PAF-KIET CoCIS Dept.
  • 17. • Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level Implementation Several issues should be considered when applying the Decorator pattern: 1. Interface conformance: A decorator object’s interface must conform to the interface of the component it decorates. 2. Omitting the abstract Decorator class: If only one responsibility is needed, don’t define abstract Decorator. Merge Decorator’s responsibility into the ConcreteDecorator. 3. Keeping Component classes light weight: Component class should be dedicated to defining an interface, no other functions. Keep it light and simple. A complex Component class might make Decorator too costly to use in quantity. 4. Changing the skin of an object versus its guts: Decorator classes should act as a layer of skin over an object. If there’s a need to change the object’s guts, use Strategy pattern. PAF-KIET CoCIS Dept.
  • 18. • Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level Builder VS Decorator PAF-KIET CoCIS Dept.
  • 19. • Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level PAF-KIET CoCIS Dept. Builder VS Decorator
  • 20. • Click to edit Master text styles – Second level • Third level – Fourth level » Fifth level Related Patterns PAF-KIET CoCIS Dept. •Adapter: A decorator is different from an adapter in that a decorator only changes an object‘s responsibilities, not its interface; an adapter will give an object a completely new interface. •Strategy : A decorator lets you change the skin of an object; a strategy lets you change the guts. These are two alternative ways of changing an object.