SlideShare a Scribd company logo
1 of 11
DESIGN PATTERN
READING GROUP –
DECORATOR PATTERN
2014/May/30
Vincent Chu
AGENDA
What is Decorator Pattern?
Examples
Conclusion
WHAT IS DECORATOR
PATTERN?
Definition
In object-oriented
programming, the
decorator pattern (also
known as Wrapper, an
alternative naming shared
with the Adapter pattern)
is a design pattern that
allows behavior to be
added to an individual
object, either statically or
dynamically, without
affecting the behavior of
other objects from the
same class.
UML
WHAT IS DECORATOR
PATTERN?
Implementation
1. Subclass the original "Component" class into a
"Decorator" class (see UML diagram);
2. In the Decorator class, add a Component pointer as a
field;
3. Pass a Component to the Decorator constructor to
initialize the Component pointer;
4. In the Decorator class, redirect all "Component"
methods to the "Component" pointer; and
5. In the ConcreteDecorator class, override any
Component method(s) whose behavior needs to be
modified.
EXAMPLES
Cup of Joe Beauty Salon
EXAMPLE – COFFEE
EXAMPLE – BEAUTY SALON
http://www.slideshare.net/eolexe/omg-patterns-
ltdecorator-by-max-titov
Page 3
CONCLUSION
Consider following pattern before you choice Decorator
 Adapter
 Proxy
 Strategy
 Composite
CONCLUSION
Pros
1) The cure of ugly code
2) Composition over
inheritance
3) Add behavior at runtime
without class
modification
4) Behavior can be reuse
Cons
1) Tons of small classes
2) Could be not obvious for
other developers
REFERENCE
Wikipedia -
http://en.wikipedia.org/wiki/Decorator_pattern
Photo & Conclusion -
http://www.slideshare.net/eprafulla/01-introduction-
and-decorator-pattern
Beauty Salon - http://www.slideshare.net/eolexe/omg-
patterns-ltdecorator-by-max-titov
Cup of Joe -
http://www.slideshare.net/melbournepatterns/phani-
kumar-decorator-pattern
Coffee -
http://internshipblogg.wordpress.com/2012/06/13/dec
orator-pattern-power-of-extension/
THANKS FOR YOUR TIME!

More Related Content

What's hot

Decorator Design Pattern
Decorator Design PatternDecorator Design Pattern
Decorator Design PatternAdeel Riaz
 
Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSoftware Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSergey Aganezov
 
Application Of Software Design Pattern
Application Of Software Design PatternApplication Of Software Design Pattern
Application Of Software Design Patternguest46da5428
 
PATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design PatternsPATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design PatternsMichael Heron
 
Gof design pattern
Gof design patternGof design pattern
Gof design patternnaveen kumar
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design PatternSanae BEKKAR
 
The SOLID Principles Illustrated by Design Patterns
The SOLID Principles Illustrated by Design PatternsThe SOLID Principles Illustrated by Design Patterns
The SOLID Principles Illustrated by Design PatternsHayim Makabee
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1Shahzad
 
Design pattern - Facade Pattern
Design pattern - Facade PatternDesign pattern - Facade Pattern
Design pattern - Facade PatternMudasir Qazi
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)paramisoft
 
Jump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternJump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternNishith Shukla
 
Bridge pattern for Dummies
Bridge pattern for DummiesBridge pattern for Dummies
Bridge pattern for DummiesTaekSoon Jang
 

What's hot (20)

Decorator Design Pattern
Decorator Design PatternDecorator Design Pattern
Decorator Design Pattern
 
What is design pattern
What is design patternWhat is design pattern
What is design pattern
 
Bridge Design Pattern
Bridge Design PatternBridge Design Pattern
Bridge Design Pattern
 
Bridge pattern
Bridge patternBridge pattern
Bridge pattern
 
Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSoftware Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural Patterns
 
Application Of Software Design Pattern
Application Of Software Design PatternApplication Of Software Design Pattern
Application Of Software Design Pattern
 
Object oriented design
Object oriented designObject oriented design
Object oriented design
 
PATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design PatternsPATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design Patterns
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
 
Bridge Pattern Derek Weeks
Bridge Pattern   Derek WeeksBridge Pattern   Derek Weeks
Bridge Pattern Derek Weeks
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
 
The SOLID Principles Illustrated by Design Patterns
The SOLID Principles Illustrated by Design PatternsThe SOLID Principles Illustrated by Design Patterns
The SOLID Principles Illustrated by Design Patterns
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
 
Design pattern - Facade Pattern
Design pattern - Facade PatternDesign pattern - Facade Pattern
Design pattern - Facade Pattern
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)
 
Bai giang-uml-11feb14
Bai giang-uml-11feb14Bai giang-uml-11feb14
Bai giang-uml-11feb14
 
Jump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternJump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design Pattern
 
Bridge pattern for Dummies
Bridge pattern for DummiesBridge pattern for Dummies
Bridge pattern for Dummies
 
Design patterns tutorials
Design patterns tutorialsDesign patterns tutorials
Design patterns tutorials
 
Composite Design Pattern
Composite Design PatternComposite Design Pattern
Composite Design Pattern
 

Viewers also liked

ديوان الإمام الشافعي مع مختارات من روائع حكمه
ديوان الإمام الشافعي مع مختارات من روائع حكمهديوان الإمام الشافعي مع مختارات من روائع حكمه
ديوان الإمام الشافعي مع مختارات من روائع حكمهRamzi Mandhouj
 
قصص الصحابة و الصالحين . محمد متولي الشعراوي . مكتبة أبوالعيس
قصص الصحابة و الصالحين . محمد متولي الشعراوي . مكتبة أبوالعيسقصص الصحابة و الصالحين . محمد متولي الشعراوي . مكتبة أبوالعيس
قصص الصحابة و الصالحين . محمد متولي الشعراوي . مكتبة أبوالعيسPUSH BUTTIONS
 
Reading group schedule
Reading group scheduleReading group schedule
Reading group scheduleEmily Lobao
 
Reading Group Presentation
Reading Group PresentationReading Group Presentation
Reading Group PresentationJia
 
2 types of businesses business studies
2 types of businesses business studies2 types of businesses business studies
2 types of businesses business studiesPhoebe Riorden
 
Power point
Power pointPower point
Power pointwiratra
 
Fundraising Planning Worksheet
Fundraising Planning WorksheetFundraising Planning Worksheet
Fundraising Planning Worksheet4Good.org
 

Viewers also liked (9)

ديوان الإمام الشافعي مع مختارات من روائع حكمه
ديوان الإمام الشافعي مع مختارات من روائع حكمهديوان الإمام الشافعي مع مختارات من روائع حكمه
ديوان الإمام الشافعي مع مختارات من روائع حكمه
 
قصص الصحابة و الصالحين . محمد متولي الشعراوي . مكتبة أبوالعيس
قصص الصحابة و الصالحين . محمد متولي الشعراوي . مكتبة أبوالعيسقصص الصحابة و الصالحين . محمد متولي الشعراوي . مكتبة أبوالعيس
قصص الصحابة و الصالحين . محمد متولي الشعراوي . مكتبة أبوالعيس
 
Reading group schedule
Reading group scheduleReading group schedule
Reading group schedule
 
Reading Group Presentation
Reading Group PresentationReading Group Presentation
Reading Group Presentation
 
Skillwise Consulting_Soft skills
Skillwise Consulting_Soft skillsSkillwise Consulting_Soft skills
Skillwise Consulting_Soft skills
 
2 types of businesses business studies
2 types of businesses business studies2 types of businesses business studies
2 types of businesses business studies
 
Computer Fundamental
Computer FundamentalComputer Fundamental
Computer Fundamental
 
Power point
Power pointPower point
Power point
 
Fundraising Planning Worksheet
Fundraising Planning WorksheetFundraising Planning Worksheet
Fundraising Planning Worksheet
 

Similar to Design pattern reading group – decorator pattern

Design Patterns
Design PatternsDesign Patterns
Design Patternsadil raja
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patternsAmit Kabra
 
Andy Bulka Pattern Automation
Andy Bulka Pattern AutomationAndy Bulka Pattern Automation
Andy Bulka Pattern Automationtcab22
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and DesignDr. C.V. Suresh Babu
 
Design Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldDesign Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldSaurabh Moody
 
Refactoring: Code it Clean
Refactoring: Code it CleanRefactoring: Code it Clean
Refactoring: Code it CleanAliGermiyanoglu
 
Design pattern in an expressive language java script
Design pattern in an expressive language java scriptDesign pattern in an expressive language java script
Design pattern in an expressive language java scriptAmit Thakkar
 
Software architecture with SOA modeling Flavor
Software architecture with SOA modeling FlavorSoftware architecture with SOA modeling Flavor
Software architecture with SOA modeling FlavorMohamed Zakarya Abdelgawad
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design patternMindfire Solutions
 
P Training Presentation
P Training PresentationP Training Presentation
P Training PresentationGaurav Tyagi
 
Software engineering: design for reuse
Software engineering: design for reuseSoftware engineering: design for reuse
Software engineering: design for reuseMarco Brambilla
 
Apply Template Method Pattern in Report Implementation
Apply Template Method Pattern in Report ImplementationApply Template Method Pattern in Report Implementation
Apply Template Method Pattern in Report ImplementationGuo Albert
 
Design Patterns
Design PatternsDesign Patterns
Design Patternsimedo.de
 
Implementing the Adapter Design Pattern
Implementing the Adapter Design PatternImplementing the Adapter Design Pattern
Implementing the Adapter Design PatternProdigyView
 

Similar to Design pattern reading group – decorator pattern (20)

Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patterns
 
Andy Bulka Pattern Automation
Andy Bulka Pattern AutomationAndy Bulka Pattern Automation
Andy Bulka Pattern Automation
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and Design
 
Design Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldDesign Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The World
 
Refactoring: Code it Clean
Refactoring: Code it CleanRefactoring: Code it Clean
Refactoring: Code it Clean
 
L05 Frameworks
L05 FrameworksL05 Frameworks
L05 Frameworks
 
Design pattern in an expressive language java script
Design pattern in an expressive language java scriptDesign pattern in an expressive language java script
Design pattern in an expressive language java script
 
Software architecture with SOA modeling Flavor
Software architecture with SOA modeling FlavorSoftware architecture with SOA modeling Flavor
Software architecture with SOA modeling Flavor
 
uml reference package_diagram
uml reference package_diagramuml reference package_diagram
uml reference package_diagram
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 
Software engineering: design for reuse
Software engineering: design for reuseSoftware engineering: design for reuse
Software engineering: design for reuse
 
Apply Template Method Pattern in Report Implementation
Apply Template Method Pattern in Report ImplementationApply Template Method Pattern in Report Implementation
Apply Template Method Pattern in Report Implementation
 
Introduction to Design Patterns
Introduction to Design PatternsIntroduction to Design Patterns
Introduction to Design Patterns
 
Angular2
Angular2Angular2
Angular2
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Implementing the Adapter Design Pattern
Implementing the Adapter Design PatternImplementing the Adapter Design Pattern
Implementing the Adapter Design Pattern
 
Design patterns
Design patternsDesign patterns
Design patterns
 
ITSE_10(UML,OO).pptx
ITSE_10(UML,OO).pptxITSE_10(UML,OO).pptx
ITSE_10(UML,OO).pptx
 

Recently uploaded

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Recently uploaded (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

Design pattern reading group – decorator pattern

  • 1. DESIGN PATTERN READING GROUP – DECORATOR PATTERN 2014/May/30 Vincent Chu
  • 2. AGENDA What is Decorator Pattern? Examples Conclusion
  • 3. WHAT IS DECORATOR PATTERN? Definition In object-oriented programming, the decorator pattern (also known as Wrapper, an alternative naming shared with the Adapter pattern) is a design pattern that allows behavior to be added to an individual object, either statically or dynamically, without affecting the behavior of other objects from the same class. UML
  • 4. WHAT IS DECORATOR PATTERN? Implementation 1. Subclass the original "Component" class into a "Decorator" class (see UML diagram); 2. In the Decorator class, add a Component pointer as a field; 3. Pass a Component to the Decorator constructor to initialize the Component pointer; 4. In the Decorator class, redirect all "Component" methods to the "Component" pointer; and 5. In the ConcreteDecorator class, override any Component method(s) whose behavior needs to be modified.
  • 5. EXAMPLES Cup of Joe Beauty Salon
  • 7. EXAMPLE – BEAUTY SALON http://www.slideshare.net/eolexe/omg-patterns- ltdecorator-by-max-titov Page 3
  • 8. CONCLUSION Consider following pattern before you choice Decorator  Adapter  Proxy  Strategy  Composite
  • 9. CONCLUSION Pros 1) The cure of ugly code 2) Composition over inheritance 3) Add behavior at runtime without class modification 4) Behavior can be reuse Cons 1) Tons of small classes 2) Could be not obvious for other developers
  • 10. REFERENCE Wikipedia - http://en.wikipedia.org/wiki/Decorator_pattern Photo & Conclusion - http://www.slideshare.net/eprafulla/01-introduction- and-decorator-pattern Beauty Salon - http://www.slideshare.net/eolexe/omg- patterns-ltdecorator-by-max-titov Cup of Joe - http://www.slideshare.net/melbournepatterns/phani- kumar-decorator-pattern Coffee - http://internshipblogg.wordpress.com/2012/06/13/dec orator-pattern-power-of-extension/