SlideShare una empresa de Scribd logo
1 de 20
• 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.

Más contenido relacionado

La actualidad más candente

Chain of responsibility
Chain of responsibilityChain of responsibility
Chain of responsibilityShakil Ahmed
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design PatternShahriar Hyder
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)paramisoft
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern PresentationJAINIK PATEL
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patternsAmit Kabra
 
Observer Software Design Pattern
Observer Software Design Pattern Observer Software Design Pattern
Observer Software Design Pattern Nirthika Rajendran
 
Unit 2(advanced class modeling & state diagram)
Unit  2(advanced class modeling & state diagram)Unit  2(advanced class modeling & state diagram)
Unit 2(advanced class modeling & state diagram)Manoj Reddy
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1Shahzad
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design PatternSanae BEKKAR
 
Java Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | EdurekaJava Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | EdurekaEdureka!
 
Observer design pattern
Observer design patternObserver design pattern
Observer design patternSara Torkey
 
Design Patterns
Design PatternsDesign Patterns
Design Patternssoms_1
 
Design Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternDesign Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternMudasir Qazi
 

La actualidad más candente (20)

Chain of responsibility
Chain of responsibilityChain of responsibility
Chain of responsibility
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design Pattern
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern Presentation
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patterns
 
Observer Software Design Pattern
Observer Software Design Pattern Observer Software Design Pattern
Observer Software Design Pattern
 
Bridge pattern
Bridge patternBridge pattern
Bridge pattern
 
Unit 2(advanced class modeling & state diagram)
Unit  2(advanced class modeling & state diagram)Unit  2(advanced class modeling & state diagram)
Unit 2(advanced class modeling & state diagram)
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
 
Composite design pattern
Composite design patternComposite design pattern
Composite design pattern
 
Prototype pattern
Prototype patternPrototype pattern
Prototype pattern
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
 
Facade pattern
Facade patternFacade pattern
Facade pattern
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
 
Java Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | EdurekaJava Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | Edureka
 
Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
 
Flyweight pattern
Flyweight patternFlyweight pattern
Flyweight pattern
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Design Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternDesign Pattern - Factory Method Pattern
Design Pattern - Factory Method Pattern
 

Similar a 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 FundamentalsIDERA 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
 
Maintenance & Re-Engineering of Software
Maintenance & Re-Engineering of SoftwareMaintenance & Re-Engineering of Software
Maintenance & Re-Engineering of SoftwareAdeel Riaz
 
MongoDB and MongoMK Source Event
MongoDB and MongoMK Source EventMongoDB and MongoMK Source Event
MongoDB and MongoMK Source EventYuval 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 OneSarah 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 ImplementationJonathan 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 DrupalDrupalcampAtlanta2012
 
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 bankingJakub 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 AssessmentRita 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
 
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 DinosaursFrances 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 DublinSuzanne Dergacheva
 
Few minutes To better Code - Refactoring
Few minutes To better Code - RefactoringFew minutes To better Code - Refactoring
Few minutes To better Code - RefactoringDiaa 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 WorldFlorida State University
 
Enterprise DevOps
Enterprise DevOpsEnterprise DevOps
Enterprise DevOpsVistara
 

Similar a 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
 

Último

How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 

Último (20)

How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 

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.