SlideShare a Scribd company logo
S.Ducasse 1
QuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.
Stéphane Ducasse
Stephane.Ducasse@univ-savoie.fr
http://www.listic.univ-savoie.fr/~ducasse/
Decorator
S.Ducasse 2
License: CC-Attribution-ShareAlike 2.0
http://creativecommons.org/licenses/by-sa/2.0/
S.Ducasse 3
Decorator
• Attach additional responsib
• ilities to an object dynamically.
• Decorators provide a
• flexible alternative to
• subclassing for extending
• functionality.
• Aka:Wrapper
S.Ducasse 4
Decorator Intent
• Attach additional responsib ilities to an object
dynamically.
• Decorators provide a flexible alternative to
• subclassing for extending functionality.
• Aka:Wrapper
S.Ducasse 5
Motivation
• Adding behavior to individual object not entire class
• scrollbar
• border
S.Ducasse 6
Inheritance?
• Does not work well
• Too much combination border, color, scrollbars,
bounds, translation...
• To static: Clients cannot control when to put a border
or not...
S.Ducasse 7
Decorator
• Enclose the component into another one that adds
border...in another one that adds scrollbar...
• The decorator conforms to the interface of the
component it decorates so that its presence is
transparent to the component's clients.
• The decorator forwards requests to the component
and may perform additional actions (such as drawing a
border) before or after forwarding
S.Ducasse 8
Decorator Solution
S.Ducasse 9
Applicability
• When responsibilities can be withdrawn
• When responsibilities can be added transparently
• When subclassing is not possible (combination
explosion)
S.Ducasse 10
Possible Decorator Structure
S.Ducasse 11
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.
S.Ducasse 12
Collaborations
• Decorator forwards requests to its Component
object. It may optionally perform additional operations
before and after forwarding the request.
S.Ducasse 13
About Identity
• A decorator and its component aren't identical.
• A decorator acts as a transparent enclosure. But from
an object identity point of view, a decorated
component is not identical to the component itself.
• If the decorator is wrapping, then identity of the
object may change.
• Good at construction time, but else should “adapt”
the references from the decorated to the decorator.
S.Ducasse 14
Consequences
• More flexibility than static inheritance. Dynamic
addition of properties
• Avoids feature-laden classes high up in the hierarchy.
• Lots of little objects.
S.Ducasse 15
Implementation
• Interface conformance. A decorator object's
interface must conform to the interface of the
component it decorates. ConcreteDecorator classes
must therefore inherit from a common class (at least
in C++).
• Omitting the abstract Decorator class. There's no
need to define an abstract Decorator class when you
only need to add one responsibility.
• Keeping Component classes lightweight.
Component should specify an interface, decorators
are then easier to define
S.Ducasse 16
Wrapping or not? Conforming or not
• With decorator
• With strategies
S.Ducasse 17
Strategies?
• Strategies are a better choice when the Component
class is heavyweight, thereby making the Decorator
pattern too costly to apply.
• The Strategy-based approach might require modifying
the component to accommodate new extensions.
• a strategy can have its own specialized interface,
• a decorator's interface must conform to the
component's.
• A strategy needs only define the interface for
rendering a border, which means that the strategy can
be lightweight even if the Component class is
heavyweight.
S.Ducasse 18
Known Uses
• VisualWorks Wrapper hierarchy
• Stream Decorators inVisualWorks:
• BOSSTransporter is a stream decorator
• FormattedStream is a stream decorator

More Related Content

PPT
Stoop 440-adaptor
The World of Smalltalk
 
PPT
Stoop 422-naming idioms
The World of Smalltalk
 
PPT
Stoop 433-chain
The World of Smalltalk
 
PDF
Stoop 400-metaclass only
The World of Smalltalk
 
PPT
Stoop 421-design heuristics
The World of Smalltalk
 
PPT
Stoop ed-unit ofreuse
The World of Smalltalk
 
PPT
Stoop 450-s unit
The World of Smalltalk
 
PPT
Stoop 301-internal objectstructureinvw
The World of Smalltalk
 
Stoop 440-adaptor
The World of Smalltalk
 
Stoop 422-naming idioms
The World of Smalltalk
 
Stoop 433-chain
The World of Smalltalk
 
Stoop 400-metaclass only
The World of Smalltalk
 
Stoop 421-design heuristics
The World of Smalltalk
 
Stoop ed-unit ofreuse
The World of Smalltalk
 
Stoop 450-s unit
The World of Smalltalk
 
Stoop 301-internal objectstructureinvw
The World of Smalltalk
 

Viewers also liked (20)

PPT
10 - OOP - Inheritance (b)
The World of Smalltalk
 
PPT
Double Dispatch
The World of Smalltalk
 
PPT
12 - Conditions and Loops
The World of Smalltalk
 
PPT
Stoop 437-proxy
The World of Smalltalk
 
PPT
14 - Exceptions
The World of Smalltalk
 
PPT
08 refactoring
The World of Smalltalk
 
PPT
5 - OOP - Smalltalk in a Nutshell (c)
The World of Smalltalk
 
PPT
Stoop 423-smalltalk idioms
The World of Smalltalk
 
PPT
Stoop 300-block optimizationinvw
The World of Smalltalk
 
PPT
Stoop 436-strategy
The World of Smalltalk
 
PPT
10 - OOP - Inheritance (a)
The World of Smalltalk
 
PPT
Stoop ed-class forreuse
The World of Smalltalk
 
PPT
Stoop ed-some principles
The World of Smalltalk
 
PPT
12 virtualmachine
The World of Smalltalk
 
PPT
Stoop 414-smalltalk elementsofdesign
The World of Smalltalk
 
PPT
Debugging VisualWorks
The World of Smalltalk
 
PPT
Stoop sed-class initialization
The World of Smalltalk
 
PPT
Stoop metaclasses
The World of Smalltalk
 
PPT
Stoop 423-some designpatterns
The World of Smalltalk
 
PPT
11 - OOP - Numbers
The World of Smalltalk
 
10 - OOP - Inheritance (b)
The World of Smalltalk
 
Double Dispatch
The World of Smalltalk
 
12 - Conditions and Loops
The World of Smalltalk
 
Stoop 437-proxy
The World of Smalltalk
 
14 - Exceptions
The World of Smalltalk
 
08 refactoring
The World of Smalltalk
 
5 - OOP - Smalltalk in a Nutshell (c)
The World of Smalltalk
 
Stoop 423-smalltalk idioms
The World of Smalltalk
 
Stoop 300-block optimizationinvw
The World of Smalltalk
 
Stoop 436-strategy
The World of Smalltalk
 
10 - OOP - Inheritance (a)
The World of Smalltalk
 
Stoop ed-class forreuse
The World of Smalltalk
 
Stoop ed-some principles
The World of Smalltalk
 
12 virtualmachine
The World of Smalltalk
 
Stoop 414-smalltalk elementsofdesign
The World of Smalltalk
 
Debugging VisualWorks
The World of Smalltalk
 
Stoop sed-class initialization
The World of Smalltalk
 
Stoop metaclasses
The World of Smalltalk
 
Stoop 423-some designpatterns
The World of Smalltalk
 
11 - OOP - Numbers
The World of Smalltalk
 
Ad

Similar to Stoop 439-decorator (20)

PPTX
Bridging the Divide between Architecture and Code (Germany JUGs version)
Chris Chedgey
 
PPT
Stoop ed-subtyping subclassing
The World of Smalltalk
 
PPT
Design patterns structuralpatterns(thedecoratorpattern)
APU
 
PPT
Stoop ed-frameworks
The World of Smalltalk
 
PPT
7 - OOP - OO Concepts
The World of Smalltalk
 
PPTX
Decorator design pattern
Neelima Sanagavarapu
 
PPTX
Decorator Pattern
Dimuthu Anuraj
 
PPTX
Bridging the divide between architecture and code (US version)
Chris Chedgey
 
PPTX
Cs 1023 lec 8 design pattern (week 2)
stanbridge
 
PDF
Introduction to Docker, Devops Virtualization and configuration management
AbhinShyam1
 
PPT
Stoop ed-lod
The World of Smalltalk
 
PPTX
Docker in a big company
Docker, Inc.
 
PDF
Rails Presenters
Tom Ridge
 
PPT
Stoop 434-composite
The World of Smalltalk
 
PPS
Exhibits and Presenters
atifzia14
 
PDF
Lessons Learned from Dockerizing Spark Workloads: Spark Summit East talk by T...
Spark Summit
 
PPTX
Brief introduction to Object Oriented Analysis and Design
Amrullah Zunzunia
 
PPTX
Design Pattern lecture 3
Julie Iskander
 
PPTX
2012 02-modularity-animated-120309090811-phpapp02
rittelfischer
 
Bridging the Divide between Architecture and Code (Germany JUGs version)
Chris Chedgey
 
Stoop ed-subtyping subclassing
The World of Smalltalk
 
Design patterns structuralpatterns(thedecoratorpattern)
APU
 
Stoop ed-frameworks
The World of Smalltalk
 
7 - OOP - OO Concepts
The World of Smalltalk
 
Decorator design pattern
Neelima Sanagavarapu
 
Decorator Pattern
Dimuthu Anuraj
 
Bridging the divide between architecture and code (US version)
Chris Chedgey
 
Cs 1023 lec 8 design pattern (week 2)
stanbridge
 
Introduction to Docker, Devops Virtualization and configuration management
AbhinShyam1
 
Docker in a big company
Docker, Inc.
 
Rails Presenters
Tom Ridge
 
Stoop 434-composite
The World of Smalltalk
 
Exhibits and Presenters
atifzia14
 
Lessons Learned from Dockerizing Spark Workloads: Spark Summit East talk by T...
Spark Summit
 
Brief introduction to Object Oriented Analysis and Design
Amrullah Zunzunia
 
Design Pattern lecture 3
Julie Iskander
 
2012 02-modularity-animated-120309090811-phpapp02
rittelfischer
 
Ad

More from The World of Smalltalk (18)

PDF
05 seaside canvas
The World of Smalltalk
 
PPT
99 questions
The World of Smalltalk
 
PPT
11 bytecode
The World of Smalltalk
 
PPT
10 reflection
The World of Smalltalk
 
PPT
09 metaclasses
The World of Smalltalk
 
PPT
07 bestpractice
The World of Smalltalk
 
PPT
06 debugging
The World of Smalltalk
 
PPT
05 seaside
The World of Smalltalk
 
PPT
03 standardclasses
The World of Smalltalk
 
PPT
Stoop sed-smells
The World of Smalltalk
 
PPT
Stoop sed-sharing ornot
The World of Smalltalk
 
PPT
Stoop sed-class initialization
The World of Smalltalk
 
PPT
Stoop ed-inheritance composition
The World of Smalltalk
 
PPT
Stoop ed-dual interface
The World of Smalltalk
 
05 seaside canvas
The World of Smalltalk
 
10 reflection
The World of Smalltalk
 
09 metaclasses
The World of Smalltalk
 
07 bestpractice
The World of Smalltalk
 
03 standardclasses
The World of Smalltalk
 
Stoop sed-smells
The World of Smalltalk
 
Stoop sed-sharing ornot
The World of Smalltalk
 
Stoop sed-class initialization
The World of Smalltalk
 
Stoop ed-inheritance composition
The World of Smalltalk
 
Stoop ed-dual interface
The World of Smalltalk
 

Recently uploaded (20)

PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Doc9.....................................
SofiaCollazos
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 

Stoop 439-decorator

  • 1. S.Ducasse 1 QuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture. Stéphane Ducasse [email protected] http://www.listic.univ-savoie.fr/~ducasse/ Decorator
  • 2. S.Ducasse 2 License: CC-Attribution-ShareAlike 2.0 http://creativecommons.org/licenses/by-sa/2.0/
  • 3. S.Ducasse 3 Decorator • Attach additional responsib • ilities to an object dynamically. • Decorators provide a • flexible alternative to • subclassing for extending • functionality. • Aka:Wrapper
  • 4. S.Ducasse 4 Decorator Intent • Attach additional responsib ilities to an object dynamically. • Decorators provide a flexible alternative to • subclassing for extending functionality. • Aka:Wrapper
  • 5. S.Ducasse 5 Motivation • Adding behavior to individual object not entire class • scrollbar • border
  • 6. S.Ducasse 6 Inheritance? • Does not work well • Too much combination border, color, scrollbars, bounds, translation... • To static: Clients cannot control when to put a border or not...
  • 7. S.Ducasse 7 Decorator • Enclose the component into another one that adds border...in another one that adds scrollbar... • The decorator conforms to the interface of the component it decorates so that its presence is transparent to the component's clients. • The decorator forwards requests to the component and may perform additional actions (such as drawing a border) before or after forwarding
  • 9. S.Ducasse 9 Applicability • When responsibilities can be withdrawn • When responsibilities can be added transparently • When subclassing is not possible (combination explosion)
  • 11. S.Ducasse 11 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.
  • 12. S.Ducasse 12 Collaborations • Decorator forwards requests to its Component object. It may optionally perform additional operations before and after forwarding the request.
  • 13. S.Ducasse 13 About Identity • A decorator and its component aren't identical. • A decorator acts as a transparent enclosure. But from an object identity point of view, a decorated component is not identical to the component itself. • If the decorator is wrapping, then identity of the object may change. • Good at construction time, but else should “adapt” the references from the decorated to the decorator.
  • 14. S.Ducasse 14 Consequences • More flexibility than static inheritance. Dynamic addition of properties • Avoids feature-laden classes high up in the hierarchy. • Lots of little objects.
  • 15. S.Ducasse 15 Implementation • Interface conformance. A decorator object's interface must conform to the interface of the component it decorates. ConcreteDecorator classes must therefore inherit from a common class (at least in C++). • Omitting the abstract Decorator class. There's no need to define an abstract Decorator class when you only need to add one responsibility. • Keeping Component classes lightweight. Component should specify an interface, decorators are then easier to define
  • 16. S.Ducasse 16 Wrapping or not? Conforming or not • With decorator • With strategies
  • 17. S.Ducasse 17 Strategies? • Strategies are a better choice when the Component class is heavyweight, thereby making the Decorator pattern too costly to apply. • The Strategy-based approach might require modifying the component to accommodate new extensions. • a strategy can have its own specialized interface, • a decorator's interface must conform to the component's. • A strategy needs only define the interface for rendering a border, which means that the strategy can be lightweight even if the Component class is heavyweight.
  • 18. S.Ducasse 18 Known Uses • VisualWorks Wrapper hierarchy • Stream Decorators inVisualWorks: • BOSSTransporter is a stream decorator • FormattedStream is a stream decorator