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

Viewers also liked

10 - OOP - Inheritance (b)
10 - OOP - Inheritance (b)10 - OOP - Inheritance (b)
10 - OOP - Inheritance (b)
The World of Smalltalk
 
Double Dispatch
Double DispatchDouble Dispatch
Double Dispatch
The World of Smalltalk
 
12 - Conditions and Loops
12 - Conditions and Loops12 - Conditions and Loops
12 - Conditions and Loops
The World of Smalltalk
 
Stoop 437-proxy
Stoop 437-proxyStoop 437-proxy
Stoop 437-proxy
The World of Smalltalk
 
14 - Exceptions
14 - Exceptions14 - Exceptions
14 - Exceptions
The World of Smalltalk
 
08 refactoring
08 refactoring08 refactoring
08 refactoring
The World of Smalltalk
 
5 - OOP - Smalltalk in a Nutshell (c)
5 - OOP - Smalltalk in a Nutshell (c)5 - OOP - Smalltalk in a Nutshell (c)
5 - OOP - Smalltalk in a Nutshell (c)
The World of Smalltalk
 
Stoop 423-smalltalk idioms
Stoop 423-smalltalk idiomsStoop 423-smalltalk idioms
Stoop 423-smalltalk idioms
The World of Smalltalk
 
Stoop 300-block optimizationinvw
Stoop 300-block optimizationinvwStoop 300-block optimizationinvw
Stoop 300-block optimizationinvw
The World of Smalltalk
 
Stoop 436-strategy
Stoop 436-strategyStoop 436-strategy
Stoop 436-strategy
The World of Smalltalk
 
10 - OOP - Inheritance (a)
10 - OOP - Inheritance (a)10 - OOP - Inheritance (a)
10 - OOP - Inheritance (a)
The World of Smalltalk
 
Stoop ed-class forreuse
Stoop ed-class forreuseStoop ed-class forreuse
Stoop ed-class forreuse
The World of Smalltalk
 
Stoop ed-some principles
Stoop ed-some principlesStoop ed-some principles
Stoop ed-some principles
The World of Smalltalk
 
12 virtualmachine
12 virtualmachine12 virtualmachine
12 virtualmachine
The World of Smalltalk
 
Stoop 414-smalltalk elementsofdesign
Stoop 414-smalltalk elementsofdesignStoop 414-smalltalk elementsofdesign
Stoop 414-smalltalk elementsofdesign
The World of Smalltalk
 
Debugging VisualWorks
Debugging VisualWorksDebugging VisualWorks
Debugging VisualWorks
The World of Smalltalk
 
Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
The World of Smalltalk
 
Stoop metaclasses
Stoop metaclassesStoop metaclasses
Stoop metaclasses
The World of Smalltalk
 
Stoop 423-some designpatterns
Stoop 423-some designpatternsStoop 423-some designpatterns
Stoop 423-some designpatterns
The World of Smalltalk
 
11 - OOP - Numbers
11 - OOP - Numbers11 - OOP - Numbers
11 - OOP - Numbers
The World of Smalltalk
 

Viewers also liked (20)

10 - OOP - Inheritance (b)
10 - OOP - Inheritance (b)10 - OOP - Inheritance (b)
10 - OOP - Inheritance (b)
 
Double Dispatch
Double DispatchDouble Dispatch
Double Dispatch
 
12 - Conditions and Loops
12 - Conditions and Loops12 - Conditions and Loops
12 - Conditions and Loops
 
Stoop 437-proxy
Stoop 437-proxyStoop 437-proxy
Stoop 437-proxy
 
14 - Exceptions
14 - Exceptions14 - Exceptions
14 - Exceptions
 
08 refactoring
08 refactoring08 refactoring
08 refactoring
 
5 - OOP - Smalltalk in a Nutshell (c)
5 - OOP - Smalltalk in a Nutshell (c)5 - OOP - Smalltalk in a Nutshell (c)
5 - OOP - Smalltalk in a Nutshell (c)
 
Stoop 423-smalltalk idioms
Stoop 423-smalltalk idiomsStoop 423-smalltalk idioms
Stoop 423-smalltalk idioms
 
Stoop 300-block optimizationinvw
Stoop 300-block optimizationinvwStoop 300-block optimizationinvw
Stoop 300-block optimizationinvw
 
Stoop 436-strategy
Stoop 436-strategyStoop 436-strategy
Stoop 436-strategy
 
10 - OOP - Inheritance (a)
10 - OOP - Inheritance (a)10 - OOP - Inheritance (a)
10 - OOP - Inheritance (a)
 
Stoop ed-class forreuse
Stoop ed-class forreuseStoop ed-class forreuse
Stoop ed-class forreuse
 
Stoop ed-some principles
Stoop ed-some principlesStoop ed-some principles
Stoop ed-some principles
 
12 virtualmachine
12 virtualmachine12 virtualmachine
12 virtualmachine
 
Stoop 414-smalltalk elementsofdesign
Stoop 414-smalltalk elementsofdesignStoop 414-smalltalk elementsofdesign
Stoop 414-smalltalk elementsofdesign
 
Debugging VisualWorks
Debugging VisualWorksDebugging VisualWorks
Debugging VisualWorks
 
Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
 
Stoop metaclasses
Stoop metaclassesStoop metaclasses
Stoop metaclasses
 
Stoop 423-some designpatterns
Stoop 423-some designpatternsStoop 423-some designpatterns
Stoop 423-some designpatterns
 
11 - OOP - Numbers
11 - OOP - Numbers11 - OOP - Numbers
11 - OOP - Numbers
 

Similar to Stoop 439-decorator

Bridging the Divide between Architecture and Code (Germany JUGs version)
Bridging the Divide between Architecture and Code (Germany JUGs version)Bridging the Divide between Architecture and Code (Germany JUGs version)
Bridging the Divide between Architecture and Code (Germany JUGs version)
Chris Chedgey
 
Stoop ed-subtyping subclassing
Stoop ed-subtyping subclassingStoop ed-subtyping subclassing
Stoop ed-subtyping subclassing
The World of Smalltalk
 
Design patterns structuralpatterns(thedecoratorpattern)
Design patterns structuralpatterns(thedecoratorpattern)Design patterns structuralpatterns(thedecoratorpattern)
Design patterns structuralpatterns(thedecoratorpattern)
APU
 
Stoop ed-frameworks
Stoop ed-frameworksStoop ed-frameworks
Stoop ed-frameworks
The World of Smalltalk
 
7 - OOP - OO Concepts
7 - OOP - OO Concepts7 - OOP - OO Concepts
7 - OOP - OO Concepts
The World of Smalltalk
 
Decorator design pattern
Decorator design patternDecorator design pattern
Decorator design pattern
Neelima Sanagavarapu
 
Decorator Pattern
Decorator PatternDecorator Pattern
Decorator Pattern
Dimuthu Anuraj
 
1 - OOP
1 - OOP1 - OOP
Bridging the divide between architecture and code (US version)
Bridging the divide between architecture and code (US version)Bridging the divide between architecture and code (US version)
Bridging the divide between architecture and code (US version)
Chris Chedgey
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)
stanbridge
 
Stoop ed-lod
Stoop ed-lodStoop ed-lod
Docker in a big company
Docker in a big companyDocker in a big company
Docker in a big company
Docker, Inc.
 
Rails Presenters
Rails PresentersRails Presenters
Rails Presenters
Tom Ridge
 
Stoop 434-composite
Stoop 434-compositeStoop 434-composite
Stoop 434-composite
The World of Smalltalk
 
Exhibits and Presenters
Exhibits and PresentersExhibits and Presenters
Exhibits and Presenters
atifzia14
 
Lessons Learned from Dockerizing Spark Workloads: Spark Summit East talk by T...
Lessons Learned from Dockerizing Spark Workloads: Spark Summit East talk by T...Lessons Learned from Dockerizing Spark Workloads: Spark Summit East talk by T...
Lessons Learned from Dockerizing Spark Workloads: Spark Summit East talk by T...
Spark Summit
 
Brief introduction to Object Oriented Analysis and Design
Brief introduction to Object Oriented Analysis and DesignBrief introduction to Object Oriented Analysis and Design
Brief introduction to Object Oriented Analysis and Design
Amrullah Zunzunia
 
Design Pattern lecture 3
Design Pattern lecture 3Design Pattern lecture 3
Design Pattern lecture 3
Julie Iskander
 
Restructuring
RestructuringRestructuring
2012 02-modularity-animated-120309090811-phpapp02
2012 02-modularity-animated-120309090811-phpapp022012 02-modularity-animated-120309090811-phpapp02
2012 02-modularity-animated-120309090811-phpapp02
rittelfischer
 

Similar to Stoop 439-decorator (20)

Bridging the Divide between Architecture and Code (Germany JUGs version)
Bridging the Divide between Architecture and Code (Germany JUGs version)Bridging the Divide between Architecture and Code (Germany JUGs version)
Bridging the Divide between Architecture and Code (Germany JUGs version)
 
Stoop ed-subtyping subclassing
Stoop ed-subtyping subclassingStoop ed-subtyping subclassing
Stoop ed-subtyping subclassing
 
Design patterns structuralpatterns(thedecoratorpattern)
Design patterns structuralpatterns(thedecoratorpattern)Design patterns structuralpatterns(thedecoratorpattern)
Design patterns structuralpatterns(thedecoratorpattern)
 
Stoop ed-frameworks
Stoop ed-frameworksStoop ed-frameworks
Stoop ed-frameworks
 
7 - OOP - OO Concepts
7 - OOP - OO Concepts7 - OOP - OO Concepts
7 - OOP - OO Concepts
 
Decorator design pattern
Decorator design patternDecorator design pattern
Decorator design pattern
 
Decorator Pattern
Decorator PatternDecorator Pattern
Decorator Pattern
 
1 - OOP
1 - OOP1 - OOP
1 - OOP
 
Bridging the divide between architecture and code (US version)
Bridging the divide between architecture and code (US version)Bridging the divide between architecture and code (US version)
Bridging the divide between architecture and code (US version)
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)
 
Stoop ed-lod
Stoop ed-lodStoop ed-lod
Stoop ed-lod
 
Docker in a big company
Docker in a big companyDocker in a big company
Docker in a big company
 
Rails Presenters
Rails PresentersRails Presenters
Rails Presenters
 
Stoop 434-composite
Stoop 434-compositeStoop 434-composite
Stoop 434-composite
 
Exhibits and Presenters
Exhibits and PresentersExhibits and Presenters
Exhibits and Presenters
 
Lessons Learned from Dockerizing Spark Workloads: Spark Summit East talk by T...
Lessons Learned from Dockerizing Spark Workloads: Spark Summit East talk by T...Lessons Learned from Dockerizing Spark Workloads: Spark Summit East talk by T...
Lessons Learned from Dockerizing Spark Workloads: Spark Summit East talk by T...
 
Brief introduction to Object Oriented Analysis and Design
Brief introduction to Object Oriented Analysis and DesignBrief introduction to Object Oriented Analysis and Design
Brief introduction to Object Oriented Analysis and Design
 
Design Pattern lecture 3
Design Pattern lecture 3Design Pattern lecture 3
Design Pattern lecture 3
 
Restructuring
RestructuringRestructuring
Restructuring
 
2012 02-modularity-animated-120309090811-phpapp02
2012 02-modularity-animated-120309090811-phpapp022012 02-modularity-animated-120309090811-phpapp02
2012 02-modularity-animated-120309090811-phpapp02
 

More from The World of Smalltalk

05 seaside canvas
05 seaside canvas05 seaside canvas
05 seaside canvas
The World of Smalltalk
 
99 questions
99 questions99 questions
13 traits
13 traits13 traits
11 bytecode
11 bytecode11 bytecode
10 reflection
10 reflection10 reflection
10 reflection
The World of Smalltalk
 
09 metaclasses
09 metaclasses09 metaclasses
09 metaclasses
The World of Smalltalk
 
07 bestpractice
07 bestpractice07 bestpractice
07 bestpractice
The World of Smalltalk
 
06 debugging
06 debugging06 debugging
05 seaside
05 seaside05 seaside
04 idioms
04 idioms04 idioms
03 standardclasses
03 standardclasses03 standardclasses
03 standardclasses
The World of Smalltalk
 
02 basics
02 basics02 basics
01 intro
01 intro01 intro
Stoop sed-smells
Stoop sed-smellsStoop sed-smells
Stoop sed-smells
The World of Smalltalk
 
Stoop sed-sharing ornot
Stoop sed-sharing ornotStoop sed-sharing ornot
Stoop sed-sharing ornot
The World of Smalltalk
 
Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
The World of Smalltalk
 
Stoop ed-inheritance composition
Stoop ed-inheritance compositionStoop ed-inheritance composition
Stoop ed-inheritance composition
The World of Smalltalk
 
Stoop ed-dual interface
Stoop ed-dual interfaceStoop ed-dual interface
Stoop ed-dual interface
The World of Smalltalk
 

More from The World of Smalltalk (18)

05 seaside canvas
05 seaside canvas05 seaside canvas
05 seaside canvas
 
99 questions
99 questions99 questions
99 questions
 
13 traits
13 traits13 traits
13 traits
 
11 bytecode
11 bytecode11 bytecode
11 bytecode
 
10 reflection
10 reflection10 reflection
10 reflection
 
09 metaclasses
09 metaclasses09 metaclasses
09 metaclasses
 
07 bestpractice
07 bestpractice07 bestpractice
07 bestpractice
 
06 debugging
06 debugging06 debugging
06 debugging
 
05 seaside
05 seaside05 seaside
05 seaside
 
04 idioms
04 idioms04 idioms
04 idioms
 
03 standardclasses
03 standardclasses03 standardclasses
03 standardclasses
 
02 basics
02 basics02 basics
02 basics
 
01 intro
01 intro01 intro
01 intro
 
Stoop sed-smells
Stoop sed-smellsStoop sed-smells
Stoop sed-smells
 
Stoop sed-sharing ornot
Stoop sed-sharing ornotStoop sed-sharing ornot
Stoop sed-sharing ornot
 
Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
 
Stoop ed-inheritance composition
Stoop ed-inheritance compositionStoop ed-inheritance composition
Stoop ed-inheritance composition
 
Stoop ed-dual interface
Stoop ed-dual interfaceStoop ed-dual interface
Stoop ed-dual interface
 

Recently uploaded

How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 

Recently uploaded (20)

How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 

Stoop 439-decorator

  • 1. 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
  • 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