SlideShare a Scribd company logo
1 of 17
03 Composite and Flyweight Pattern Design Patterns © Prafulla Paraskar 2010
Composite Structural Design Pattern © Prafulla Paraskar 2010
Definition The composite pattern describes that a group of objects are to be treated in the same way as a single instance of an object.(wikipedia) © Prafulla Paraskar 2010
Composite Pattern – Explained (1/2) © Prafulla Paraskar 2010
Composite Pattern – Explained (2/2) Arranges structured hierarchies so that single components and groups of components can be treated in the same way. Makes easier to add new components. Makes client code simpler, since they do not have to know if they are dealing with one or more components. Typical operations on the components include add, remove, display, find and group. © Prafulla Paraskar 2010
Composite Pattern – UML Diagram © Prafulla Paraskar 2010
Composite Pattern – Real World Samples Files and folders in Windows Organization Tree Arithmetic Expressions like (2 + 4) * ( 5 + 6) Generic containers in .NET framework like list, queue, stack help implement  the composite pattern. © Prafulla Paraskar 2010
Composite Pattern – Guidelines You have : ,[object Object],You Want ,[object Object]
To treat all objects in a composite uniformly.© Prafulla Paraskar 2010
Flyweight Structural Design Pattern © Prafulla Paraskar 2010
Definition The Flyweight pattern is a pattern for sharing objects, where each instance does not contain its own state but stores it externally. This allows efficient sharing of objects to save space when there are many instances but only a few different types. (James W. Cooper – C# Design Patterns) © Prafulla Paraskar 2010
Flyweight Pattern – Explained (1/3) Designing objects down  to the lowest levels of  system "granularity”  provides optimal flexibility , but can be unacceptably  expensive in terms Row objects a p p a r e n t Row objects Character object Column object © Prafulla Paraskar 2010
Flyweight Pattern – Explained (2/3) column row row row a f e d c b g l k j i h Flyweight pool © Prafulla Paraskar 2010
Flyweight Pattern – Explained (3/3) Useful in cases where large number of objects (flyweights)required to provide “fine grain access” to the system.  Characteristics of flyweights are divided into intrinsic (inseparable) e.g. identity and extrinsic (separable) e.g. shared resource. Shared resource is taken care by a directory which manages enrollment  of participant  and provides on demand access to shared resources. Flyweights can only be created with help of a factory to enforce enrollment and sharing of resources.  © Prafulla Paraskar 2010
Flyweight Pattern – UML Diagram © Prafulla Paraskar 2010
Flyweight Pattern – Real World Samples Thumbnail representation of images in windows explorer.  Order processing system where the items are relatively similar and differ only in certain characteristics. Representation of files and folders in windows explorer. Individual cells in a spreadsheet program.  © Prafulla Paraskar 2010
Flyweight Pattern – Guidelines When: ,[object Object]

More Related Content

What's hot

Composite Design Pattern
Composite Design PatternComposite Design Pattern
Composite Design Pattern
Raj Chanchal
 
M04 Design Patterns
M04 Design PatternsM04 Design Patterns
M04 Design Patterns
Dang Tuan
 

What's hot (20)

Object oriented modeling
Object oriented modelingObject oriented modeling
Object oriented modeling
 
Encapsulation of operations, methods & persistence
Encapsulation of operations, methods & persistenceEncapsulation of operations, methods & persistence
Encapsulation of operations, methods & persistence
 
Concept of Object Oriented Programming
Concept of Object Oriented Programming Concept of Object Oriented Programming
Concept of Object Oriented Programming
 
Design patterns
Design patternsDesign patterns
Design patterns
 
PATTERNS03 - Behavioural Design Patterns
PATTERNS03 - Behavioural Design PatternsPATTERNS03 - Behavioural Design Patterns
PATTERNS03 - Behavioural Design Patterns
 
Sda 8
Sda   8Sda   8
Sda 8
 
Object database standards, languages and design
Object database standards, languages and designObject database standards, languages and design
Object database standards, languages and design
 
Oops slide
Oops slide Oops slide
Oops slide
 
Oops
OopsOops
Oops
 
Composite Design Pattern
Composite Design PatternComposite Design Pattern
Composite Design Pattern
 
Object oriented programming concept
Object oriented programming conceptObject oriented programming concept
Object oriented programming concept
 
[OOP - Lec 08] Encapsulation (Information Hiding)
[OOP - Lec 08] Encapsulation (Information Hiding)[OOP - Lec 08] Encapsulation (Information Hiding)
[OOP - Lec 08] Encapsulation (Information Hiding)
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate Framework
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Ashish oot
Ashish ootAshish oot
Ashish oot
 
M04 Design Patterns
M04 Design PatternsM04 Design Patterns
M04 Design Patterns
 
Visitor pattern
Visitor patternVisitor pattern
Visitor pattern
 
Oop concepts
Oop conceptsOop concepts
Oop concepts
 
All 23 Design patterns in one page front and back
All 23 Design patterns in one page front and backAll 23 Design patterns in one page front and back
All 23 Design patterns in one page front and back
 
encapsulation
encapsulationencapsulation
encapsulation
 

Viewers also liked

Retail Institution Report
Retail Institution ReportRetail Institution Report
Retail Institution Report
Fridz Felisco
 

Viewers also liked (12)

Flyweight Pattern
Flyweight PatternFlyweight Pattern
Flyweight Pattern
 
Design Patterns - 01 Introduction and Decorator Pattern
Design Patterns - 01 Introduction and Decorator PatternDesign Patterns - 01 Introduction and Decorator Pattern
Design Patterns - 01 Introduction and Decorator Pattern
 
Retail Institution Report
Retail Institution ReportRetail Institution Report
Retail Institution Report
 
Javascript Common Design Patterns
Javascript Common Design PatternsJavascript Common Design Patterns
Javascript Common Design Patterns
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design Pattern
 
Design Patterns - 04 Adapter and Facade Pattern
Design Patterns - 04 Adapter and Facade PatternDesign Patterns - 04 Adapter and Facade Pattern
Design Patterns - 04 Adapter and Facade Pattern
 
Design Patterns - Part 1 of 2
Design Patterns - Part 1 of 2Design Patterns - Part 1 of 2
Design Patterns - Part 1 of 2
 
Command pattern
Command patternCommand pattern
Command pattern
 
Command and Adapter Pattern
Command and Adapter PatternCommand and Adapter Pattern
Command and Adapter Pattern
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design Pattern
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 

Similar to Design Patterns - 03 Composite and Flyweight Pattern

Software Architecture and Project Management module III : PATTERN OF ENTERPRISE
Software Architecture and Project Management module III : PATTERN OF ENTERPRISESoftware Architecture and Project Management module III : PATTERN OF ENTERPRISE
Software Architecture and Project Management module III : PATTERN OF ENTERPRISE
sreeja_rajesh
 
UML Design Class Diagrams (2014)
UML Design Class Diagrams (2014)UML Design Class Diagrams (2014)
UML Design Class Diagrams (2014)
Miriam Ruiz
 
Design pattern (week 2)
Design pattern (week 2)Design pattern (week 2)
Design pattern (week 2)
stanbridge
 
Applied xml programming for microsoft
Applied xml programming for microsoftApplied xml programming for microsoft
Applied xml programming for microsoft
Raghu nath
 
Assignment # 2PreliminariesImportant Points· Evidence of acad.docx
Assignment  # 2PreliminariesImportant Points· Evidence of acad.docxAssignment  # 2PreliminariesImportant Points· Evidence of acad.docx
Assignment # 2PreliminariesImportant Points· Evidence of acad.docx
jane3dyson92312
 
Part2- The Atomic Information Resource
Part2- The Atomic Information ResourcePart2- The Atomic Information Resource
Part2- The Atomic Information Resource
JEAN-MICHEL LETENNIER
 

Similar to Design Patterns - 03 Composite and Flyweight Pattern (20)

Design patterns
Design patternsDesign patterns
Design patterns
 
designpatterns-.pdf
designpatterns-.pdfdesignpatterns-.pdf
designpatterns-.pdf
 
UK INCOSE Annual Systems Engineering Conference. Case Study - Implementing TR...
UK INCOSE Annual Systems Engineering Conference. Case Study - Implementing TR...UK INCOSE Annual Systems Engineering Conference. Case Study - Implementing TR...
UK INCOSE Annual Systems Engineering Conference. Case Study - Implementing TR...
 
Remus_3_0
Remus_3_0Remus_3_0
Remus_3_0
 
Software Architecture and Project Management module III : PATTERN OF ENTERPRISE
Software Architecture and Project Management module III : PATTERN OF ENTERPRISESoftware Architecture and Project Management module III : PATTERN OF ENTERPRISE
Software Architecture and Project Management module III : PATTERN OF ENTERPRISE
 
Making your data work harder than you do
Making your data work harder than you doMaking your data work harder than you do
Making your data work harder than you do
 
UML Design Class Diagrams (2014)
UML Design Class Diagrams (2014)UML Design Class Diagrams (2014)
UML Design Class Diagrams (2014)
 
Design pattern (week 2)
Design pattern (week 2)Design pattern (week 2)
Design pattern (week 2)
 
Applied xml programming for microsoft
Applied xml programming for microsoftApplied xml programming for microsoft
Applied xml programming for microsoft
 
Day5
Day5Day5
Day5
 
Assignment # 2PreliminariesImportant Points· Evidence of acad.docx
Assignment  # 2PreliminariesImportant Points· Evidence of acad.docxAssignment  # 2PreliminariesImportant Points· Evidence of acad.docx
Assignment # 2PreliminariesImportant Points· Evidence of acad.docx
 
UML
UMLUML
UML
 
Part2- The Atomic Information Resource
Part2- The Atomic Information ResourcePart2- The Atomic Information Resource
Part2- The Atomic Information Resource
 
QEBU: AN ADVANCED GRAPHICAL EDITOR FOR THE EBUCORE METADATA SET | Paolo PASIN...
QEBU: AN ADVANCED GRAPHICAL EDITOR FOR THE EBUCORE METADATA SET | Paolo PASIN...QEBU: AN ADVANCED GRAPHICAL EDITOR FOR THE EBUCORE METADATA SET | Paolo PASIN...
QEBU: AN ADVANCED GRAPHICAL EDITOR FOR THE EBUCORE METADATA SET | Paolo PASIN...
 
software engineering Design Patterns.pdf
software  engineering Design   Patterns.pdfsoftware  engineering Design   Patterns.pdf
software engineering Design Patterns.pdf
 
Terraform modules restructured
Terraform modules restructuredTerraform modules restructured
Terraform modules restructured
 
Terraform Modules Restructured
Terraform Modules RestructuredTerraform Modules Restructured
Terraform Modules Restructured
 
Ch08
Ch08Ch08
Ch08
 
Ch08
Ch08Ch08
Ch08
 
D0373024030
D0373024030D0373024030
D0373024030
 

Recently uploaded

NO1 Best Best Amil In Rawalpindi Bangali Baba In Rawalpindi jadu tona karne w...
NO1 Best Best Amil In Rawalpindi Bangali Baba In Rawalpindi jadu tona karne w...NO1 Best Best Amil In Rawalpindi Bangali Baba In Rawalpindi jadu tona karne w...
NO1 Best Best Amil In Rawalpindi Bangali Baba In Rawalpindi jadu tona karne w...
Amil baba
 
Knowing, Understanding and Planning Cities- Role and Relevance Physical Plan...
Knowing, Understanding and Planning Cities- Role and Relevance  Physical Plan...Knowing, Understanding and Planning Cities- Role and Relevance  Physical Plan...
Knowing, Understanding and Planning Cities- Role and Relevance Physical Plan...
JIT KUMAR GUPTA
 
一比一原版谢菲尔德大学毕业证成绩单如何办理
一比一原版谢菲尔德大学毕业证成绩单如何办理一比一原版谢菲尔德大学毕业证成绩单如何办理
一比一原版谢菲尔德大学毕业证成绩单如何办理
cyebo
 
一比一原版格林威治大学毕业证成绩单如何办理
一比一原版格林威治大学毕业证成绩单如何办理一比一原版格林威治大学毕业证成绩单如何办理
一比一原版格林威治大学毕业证成绩单如何办理
cyebo
 
Week 11 Mini-Tasks.pptxjjjjjjjjjjjjjjjjjjjj
Week 11 Mini-Tasks.pptxjjjjjjjjjjjjjjjjjjjjWeek 11 Mini-Tasks.pptxjjjjjjjjjjjjjjjjjjjj
Week 11 Mini-Tasks.pptxjjjjjjjjjjjjjjjjjjjj
joshuaclack73
 

Recently uploaded (20)

NO1 Best Best Amil In Rawalpindi Bangali Baba In Rawalpindi jadu tona karne w...
NO1 Best Best Amil In Rawalpindi Bangali Baba In Rawalpindi jadu tona karne w...NO1 Best Best Amil In Rawalpindi Bangali Baba In Rawalpindi jadu tona karne w...
NO1 Best Best Amil In Rawalpindi Bangali Baba In Rawalpindi jadu tona karne w...
 
Heidi Livengood's Professional CADD Portfolio
Heidi Livengood's Professional CADD PortfolioHeidi Livengood's Professional CADD Portfolio
Heidi Livengood's Professional CADD Portfolio
 
The Impact of Artificial Intelligence on Modern Healthcare.pptx
The Impact of Artificial Intelligence on Modern Healthcare.pptxThe Impact of Artificial Intelligence on Modern Healthcare.pptx
The Impact of Artificial Intelligence on Modern Healthcare.pptx
 
iF_Design_Trend_Report_twentytwenrythree
iF_Design_Trend_Report_twentytwenrythreeiF_Design_Trend_Report_twentytwenrythree
iF_Design_Trend_Report_twentytwenrythree
 
Abdulaziz Tariq Abdulaziz Mustafa CV 2024
Abdulaziz Tariq Abdulaziz Mustafa CV 2024Abdulaziz Tariq Abdulaziz Mustafa CV 2024
Abdulaziz Tariq Abdulaziz Mustafa CV 2024
 
And that's about to change! (Service Design Drinks Berlin May 2024)
And that's about to change! (Service Design Drinks Berlin May 2024)And that's about to change! (Service Design Drinks Berlin May 2024)
And that's about to change! (Service Design Drinks Berlin May 2024)
 
Week of Action 2022_EIT Climate-KIC_Headers
Week of Action 2022_EIT Climate-KIC_HeadersWeek of Action 2022_EIT Climate-KIC_Headers
Week of Action 2022_EIT Climate-KIC_Headers
 
Claire's designing portfolio presentation
Claire's designing portfolio presentationClaire's designing portfolio presentation
Claire's designing portfolio presentation
 
Levi's Advertisement and camapign design
Levi's Advertisement and camapign designLevi's Advertisement and camapign design
Levi's Advertisement and camapign design
 
Knowing, Understanding and Planning Cities- Role and Relevance Physical Plan...
Knowing, Understanding and Planning Cities- Role and Relevance  Physical Plan...Knowing, Understanding and Planning Cities- Role and Relevance  Physical Plan...
Knowing, Understanding and Planning Cities- Role and Relevance Physical Plan...
 
CADD 141 - BIRD Scooter - Cup Holder Photos.pdf
CADD 141 - BIRD Scooter - Cup Holder Photos.pdfCADD 141 - BIRD Scooter - Cup Holder Photos.pdf
CADD 141 - BIRD Scooter - Cup Holder Photos.pdf
 
一比一原版谢菲尔德大学毕业证成绩单如何办理
一比一原版谢菲尔德大学毕业证成绩单如何办理一比一原版谢菲尔德大学毕业证成绩单如何办理
一比一原版谢菲尔德大学毕业证成绩单如何办理
 
一比一原版格林威治大学毕业证成绩单如何办理
一比一原版格林威治大学毕业证成绩单如何办理一比一原版格林威治大学毕业证成绩单如何办理
一比一原版格林威治大学毕业证成绩单如何办理
 
Design Portofolios - Licensed Architect / BIM Specialist
Design Portofolios - Licensed Architect / BIM SpecialistDesign Portofolios - Licensed Architect / BIM Specialist
Design Portofolios - Licensed Architect / BIM Specialist
 
CADD 141 - Puzzle Cube Project - Product Photos
CADD 141 - Puzzle Cube Project - Product PhotosCADD 141 - Puzzle Cube Project - Product Photos
CADD 141 - Puzzle Cube Project - Product Photos
 
Avoid these common UI/UX design mistakes
 Avoid these common UI/UX design mistakes Avoid these common UI/UX design mistakes
Avoid these common UI/UX design mistakes
 
Week 11 Mini-Tasks.pptxjjjjjjjjjjjjjjjjjjjj
Week 11 Mini-Tasks.pptxjjjjjjjjjjjjjjjjjjjjWeek 11 Mini-Tasks.pptxjjjjjjjjjjjjjjjjjjjj
Week 11 Mini-Tasks.pptxjjjjjjjjjjjjjjjjjjjj
 
Real Smart Art Infographics by Slidesgo.pptx
Real Smart Art Infographics by Slidesgo.pptxReal Smart Art Infographics by Slidesgo.pptx
Real Smart Art Infographics by Slidesgo.pptx
 
Explaining the Hidden Treasures of Modern Bathroom Design — freixadesign.pdf
Explaining the Hidden Treasures of Modern Bathroom Design — freixadesign.pdfExplaining the Hidden Treasures of Modern Bathroom Design — freixadesign.pdf
Explaining the Hidden Treasures of Modern Bathroom Design — freixadesign.pdf
 
Top 10 Website Designing Hacks for Beginners.pptx.pptx
Top 10 Website Designing Hacks for Beginners.pptx.pptxTop 10 Website Designing Hacks for Beginners.pptx.pptx
Top 10 Website Designing Hacks for Beginners.pptx.pptx
 

Design Patterns - 03 Composite and Flyweight Pattern

  • 1. 03 Composite and Flyweight Pattern Design Patterns © Prafulla Paraskar 2010
  • 2. Composite Structural Design Pattern © Prafulla Paraskar 2010
  • 3. Definition The composite pattern describes that a group of objects are to be treated in the same way as a single instance of an object.(wikipedia) © Prafulla Paraskar 2010
  • 4. Composite Pattern – Explained (1/2) © Prafulla Paraskar 2010
  • 5. Composite Pattern – Explained (2/2) Arranges structured hierarchies so that single components and groups of components can be treated in the same way. Makes easier to add new components. Makes client code simpler, since they do not have to know if they are dealing with one or more components. Typical operations on the components include add, remove, display, find and group. © Prafulla Paraskar 2010
  • 6. Composite Pattern – UML Diagram © Prafulla Paraskar 2010
  • 7. Composite Pattern – Real World Samples Files and folders in Windows Organization Tree Arithmetic Expressions like (2 + 4) * ( 5 + 6) Generic containers in .NET framework like list, queue, stack help implement the composite pattern. © Prafulla Paraskar 2010
  • 8.
  • 9. To treat all objects in a composite uniformly.© Prafulla Paraskar 2010
  • 10. Flyweight Structural Design Pattern © Prafulla Paraskar 2010
  • 11. Definition The Flyweight pattern is a pattern for sharing objects, where each instance does not contain its own state but stores it externally. This allows efficient sharing of objects to save space when there are many instances but only a few different types. (James W. Cooper – C# Design Patterns) © Prafulla Paraskar 2010
  • 12. Flyweight Pattern – Explained (1/3) Designing objects down to the lowest levels of system "granularity” provides optimal flexibility , but can be unacceptably expensive in terms Row objects a p p a r e n t Row objects Character object Column object © Prafulla Paraskar 2010
  • 13. Flyweight Pattern – Explained (2/3) column row row row a f e d c b g l k j i h Flyweight pool © Prafulla Paraskar 2010
  • 14. Flyweight Pattern – Explained (3/3) Useful in cases where large number of objects (flyweights)required to provide “fine grain access” to the system. Characteristics of flyweights are divided into intrinsic (inseparable) e.g. identity and extrinsic (separable) e.g. shared resource. Shared resource is taken care by a directory which manages enrollment of participant and provides on demand access to shared resources. Flyweights can only be created with help of a factory to enforce enrollment and sharing of resources. © Prafulla Paraskar 2010
  • 15. Flyweight Pattern – UML Diagram © Prafulla Paraskar 2010
  • 16. Flyweight Pattern – Real World Samples Thumbnail representation of images in windows explorer. Order processing system where the items are relatively similar and differ only in certain characteristics. Representation of files and folders in windows explorer. Individual cells in a spreadsheet program. © Prafulla Paraskar 2010
  • 17.
  • 18. Different kinds of state, which can be handled differently to achieve space savings
  • 19. Group of objects that share state
  • 20. Ways of computing some of the state at runtime
  • 21.
  • 22. Thank you! http://geekswithblogs.net/technomad Presentation by Prafulla Paraskar prafulla.paraskar@s1.com © 2010 S1 India Pvt. Ltd. Presentation by Prafulla Paraskar eprafulla@gmail.com © 2010 Prafulla Paraskar