SlideShare a Scribd company logo
03 Composite and Flyweight PatternDesign Patterns© Prafulla Paraskar 2010
CompositeStructural Design Pattern© Prafulla Paraskar 2010
DefinitionThe 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 SamplesFiles and folders in WindowsOrganization TreeArithmetic 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 – GuidelinesYou have :An irregular structure of objects and composites of the objects.You WantClients to ignore all but the essential differences between objects and composites of objects.
To treat all objects in a composite uniformly.© Prafulla Paraskar 2010
FlyweightStructural Design Pattern© Prafulla Paraskar 2010
DefinitionThe 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 termsRow objectsapparentRow objectsCharacter objectColumn object© Prafulla Paraskar 2010
Flyweight Pattern – Explained (2/3)columnrowrowrowafedcbglkjihFlyweight 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 SamplesThumbnail 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 – GuidelinesWhen:May objects to deal with in memory

More Related Content

PPT
Composite Design Pattern
PPT
Design pattern composite 20120413 joncash 01
PDF
Design patterns - Proxy & Composite
PPT
Flyweight pattern
PPT
Composite Pattern
PPTX
Creational pattern
PPTX
PATTERNS04 - Structural Design Patterns
PPTX
Composite design pattern
Composite Design Pattern
Design pattern composite 20120413 joncash 01
Design patterns - Proxy & Composite
Flyweight pattern
Composite Pattern
Creational pattern
PATTERNS04 - Structural Design Patterns
Composite design pattern

What's hot (20)

PPTX
Object oriented modeling
PPTX
Encapsulation of operations, methods & persistence
PPSX
Concept of Object Oriented Programming
PDF
Design patterns
PPTX
PATTERNS03 - Behavioural Design Patterns
PPTX
PPTX
Object database standards, languages and design
PPT
Oops slide
DOC
Composite Design Pattern
PPTX
Object oriented programming concept
PPTX
[OOP - Lec 08] Encapsulation (Information Hiding)
PPTX
Introduction to Hibernate Framework
DOCX
Design patterns
PPT
Ashish oot
PPT
M04 Design Patterns
ODP
Visitor pattern
PPT
Oop concepts
PDF
All 23 Design patterns in one page front and back
PPTX
encapsulation
Object oriented modeling
Encapsulation of operations, methods & persistence
Concept of Object Oriented Programming
Design patterns
PATTERNS03 - Behavioural Design Patterns
Object database standards, languages and design
Oops slide
Composite Design Pattern
Object oriented programming concept
[OOP - Lec 08] Encapsulation (Information Hiding)
Introduction to Hibernate Framework
Design patterns
Ashish oot
M04 Design Patterns
Visitor pattern
Oop concepts
All 23 Design patterns in one page front and back
encapsulation
Ad

Viewers also liked (12)

PPTX
Flyweight Pattern
PPTX
Design Patterns - 01 Introduction and Decorator Pattern
PPT
Retail Institution Report
PPTX
Javascript Common Design Patterns
PPTX
Command Design Pattern
PPTX
Design Patterns - 04 Adapter and Facade Pattern
PPTX
Design Patterns - Part 1 of 2
PPT
Command pattern
PPT
Command and Adapter Pattern
ZIP
Adapter Design Pattern
PPT
Command Design Pattern
PPTX
Adapter Design Pattern
Flyweight Pattern
Design Patterns - 01 Introduction and Decorator Pattern
Retail Institution Report
Javascript Common Design Patterns
Command Design Pattern
Design Patterns - 04 Adapter and Facade Pattern
Design Patterns - Part 1 of 2
Command pattern
Command and Adapter Pattern
Adapter Design Pattern
Command Design Pattern
Adapter Design Pattern
Ad

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

PDF
Flyweight Pattern in Python: Optimizing Memory Usage
PPTX
Fly Weight Design Pattern.pptx
PPTX
Design Patterns
PPTX
Let us understand design pattern
PPTX
ap assignmnet presentation.pptx
PPTX
GoF Design patterns I: Introduction + Structural Patterns
DOCX
Design Pattern Notes: Nagpur University
PPTX
PPTX
Design patterns Structural
PDF
Design Patterns
PPT
Design patterns ppt
PPTX
Software System Architecture-Lecture 6.pptx
PPTX
Design pattern (week 2)
PDF
UML Design Class Diagrams (2014)
PPTX
Design pattern and their application
PPT
Chapter 4_Introduction to Patterns.ppt
PPT
Chapter 4_Introduction to Patterns.ppt
PDF
Design Patterns Java programming language.pdf
PDF
Module 4: UML In Action - Design Patterns
PPT
10-design-patterns1.ppt.software engineering
Flyweight Pattern in Python: Optimizing Memory Usage
Fly Weight Design Pattern.pptx
Design Patterns
Let us understand design pattern
ap assignmnet presentation.pptx
GoF Design patterns I: Introduction + Structural Patterns
Design Pattern Notes: Nagpur University
Design patterns Structural
Design Patterns
Design patterns ppt
Software System Architecture-Lecture 6.pptx
Design pattern (week 2)
UML Design Class Diagrams (2014)
Design pattern and their application
Chapter 4_Introduction to Patterns.ppt
Chapter 4_Introduction to Patterns.ppt
Design Patterns Java programming language.pdf
Module 4: UML In Action - Design Patterns
10-design-patterns1.ppt.software engineering

Recently uploaded (20)

PPT
pump pump is a mechanism that is used to transfer a liquid from one place to ...
PDF
intro_to_rust.pptx_123456789012446789.pdf
PDF
YOW2022-BNE-MinimalViableArchitecture.pdf
PDF
Emailing DDDX-MBCaEiB.pdf DDD_Europe_2022_Intro_to_Context_Mapping_pdf-165590...
PPTX
AC-Unit1.pptx CRYPTOGRAPHIC NNNNFOR ALL
PDF
Urban Design Final Project-Site Analysis
PPTX
BSCS lesson 3.pptxnbbjbb mnbkjbkbbkbbkjb
PPTX
LITERATURE CASE STUDY DESIGN SEMESTER 5.pptx
PDF
Facade & Landscape Lighting Techniques and Trends.pptx.pdf
PPTX
HPE Aruba-master-icon-library_052722.pptx
PPT
robotS AND ROBOTICSOF HUMANS AND MACHINES
PPTX
building Planning Overview for step wise design.pptx
PDF
Introduction-to-World-Schools-format-guide.pdf
PDF
Interior Structure and Construction A1 NGYANQI
PDF
Quality Control Management for RMG, Level- 4, Certificate
PDF
Integrated-2D-and-3D-Animation-Bridging-Dimensions-for-Impactful-Storytelling...
PDF
Pongal 2026 Sponsorship Presentation - Bhopal Tamil Sangam
PPTX
Entrepreneur intro, origin, process, method
PDF
Skskkxiixijsjsnwkwkaksixindndndjdjdjsjjssk
PPTX
NEW EIA PART B - Group 5 (Section 50).pptx
pump pump is a mechanism that is used to transfer a liquid from one place to ...
intro_to_rust.pptx_123456789012446789.pdf
YOW2022-BNE-MinimalViableArchitecture.pdf
Emailing DDDX-MBCaEiB.pdf DDD_Europe_2022_Intro_to_Context_Mapping_pdf-165590...
AC-Unit1.pptx CRYPTOGRAPHIC NNNNFOR ALL
Urban Design Final Project-Site Analysis
BSCS lesson 3.pptxnbbjbb mnbkjbkbbkbbkjb
LITERATURE CASE STUDY DESIGN SEMESTER 5.pptx
Facade & Landscape Lighting Techniques and Trends.pptx.pdf
HPE Aruba-master-icon-library_052722.pptx
robotS AND ROBOTICSOF HUMANS AND MACHINES
building Planning Overview for step wise design.pptx
Introduction-to-World-Schools-format-guide.pdf
Interior Structure and Construction A1 NGYANQI
Quality Control Management for RMG, Level- 4, Certificate
Integrated-2D-and-3D-Animation-Bridging-Dimensions-for-Impactful-Storytelling...
Pongal 2026 Sponsorship Presentation - Bhopal Tamil Sangam
Entrepreneur intro, origin, process, method
Skskkxiixijsjsnwkwkaksixindndndjdjdjsjjssk
NEW EIA PART B - Group 5 (Section 50).pptx

Design Patterns - 03 Composite and Flyweight Pattern

  • 1. 03 Composite and Flyweight PatternDesign Patterns© Prafulla Paraskar 2010
  • 2. CompositeStructural Design Pattern© Prafulla Paraskar 2010
  • 3. DefinitionThe 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 SamplesFiles and folders in WindowsOrganization TreeArithmetic Expressions like (2 + 4) * ( 5 + 6)Generic containers in .NET framework like list, queue, stack help implement the composite pattern.© Prafulla Paraskar 2010
  • 8. Composite Pattern – GuidelinesYou have :An irregular structure of objects and composites of the objects.You WantClients to ignore all but the essential differences between objects and composites of objects.
  • 9. To treat all objects in a composite uniformly.© Prafulla Paraskar 2010
  • 10. FlyweightStructural Design Pattern© Prafulla Paraskar 2010
  • 11. DefinitionThe 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 termsRow objectsapparentRow objectsCharacter objectColumn object© Prafulla Paraskar 2010
  • 13. Flyweight Pattern – Explained (2/3)columnrowrowrowafedcbglkjihFlyweight 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 SamplesThumbnail 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. Flyweight Pattern – GuidelinesWhen:May objects to deal with in memory
  • 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. The application doesn’t depend on object identityYou want to:Implement a system despite sever memory constraints© Prafulla Paraskar 2010
  • 22. Thank you!http://geekswithblogs.net/technomadPresentation by Prafulla Paraskar prafulla.paraskar@s1.com© 2010 S1 India Pvt. Ltd.Presentation by Prafulla Paraskar eprafulla@gmail.com© 2010 Prafulla Paraskar