SlideShare una empresa de Scribd logo
1 de 17
Prepared By : Hasnaeen Rizvi Rahman
Astha School of Advanced Computing
   Use sharing to support large number of
    fine-grained objects efficiently.
   An application uses many objects.
   A flyweight is a shared object that can be
    used in multiple contexts simultaneously.
   It acts as an individual object in each
    context.
   The key concept is the distinction
    between intrinsic and extrinsic state.
   An application uses a large number of
    objects.
   Storage costs are high because of the
    sheer quantity of objects.
   Most objects state can be made extrinsic.
   Many groups of objects may be replaced
    by relatively few shared objects once
    extrinsic state is removed.
   The application doesn’t depends on
    object identity.
   Flyweight (Glyph)
    • Declare an interface through which flyweights can receive
      and act on extrinsic state.
   ConcreteFlyweight (Character)
    • Implements the Flyweight interface and adds storage for
      intrinsic state, if any.
   UnsharedConcreteFlyweight (Row,Column)
    • Not all flyweight subclasses need to be shared.
   Flyweight Factory
    • Creates and manages flyweight objects.
    • Ensures that flyweights are shared properly.
   Client
    • Maintains a reference to flyweights
    • Computes or stores the extrinsic state of flyweight.
   Client passes extrinsic state to flyweight.
   Client invokes FlyweightFactory to create
    Flyweight object.
   Flyweight may introduce run-time cost.
   Storage savings are a function of several
    factors:
    • The reduction in the total number of instances
      that comes from sharing.
    • The amount of intrinsic state per object.
    • Whether extrinsic state is computed or stored.
   Removing extrinsic state.
   Managing shared objects.
   Design an application which stores list of
    entities.
    • Entity: It has an ID, Name and an attribute.
    • Attribute: Attributes are composite data where each
      attribute is either a leaf or a composite. It has all
      child management operation suggested in
      composite pattern. A leaf attribute have a name and
      value. A Composite attribute have a name but no
      value. Attribute returns an XML having Name and
      Value node. The composite attribute returns the list
      of child attribute XML.
   Entity XML could be something like…
    <Entity>
      <ID>1</ID>
      <Name>Entity 1</Name>
      <Attribute>
            <Name>Entity Attribute</Name>
            <Children>
              <Attribute>
                       <Name>OrgChart</Name>
                       <Children>
                         <Attribute>
                                  <Name>Type</Name>
                                  <Value>Corporation</Value>
                         </Attribute>
                         <Attribute>
                                  <Name>Country</Name>
                                  <Value>Bangladesh</Value>
                         </Attribute>
                       </Children>
              </Attribute>
            </Children>
      </Attribute>
    </Entity>
   Use Flyweight pattern to reduce memory usage for
    attributes.

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Proxy pattern
Proxy patternProxy pattern
Proxy pattern
 
Design pattern-presentation
Design pattern-presentationDesign pattern-presentation
Design pattern-presentation
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
 
Composite pattern
Composite patternComposite pattern
Composite pattern
 
The State Design Pattern
The State Design PatternThe State Design Pattern
The State Design Pattern
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Proxy Design Pattern
Proxy Design PatternProxy Design Pattern
Proxy Design Pattern
 
Proxy design pattern
Proxy design patternProxy design pattern
Proxy design pattern
 
Bridge pattern
Bridge patternBridge pattern
Bridge pattern
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Composite Design Pattern
Composite Design PatternComposite Design Pattern
Composite Design Pattern
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern Presentation
 
Prototype design patterns
Prototype design patternsPrototype design patterns
Prototype design patterns
 
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
 
Decorator design pattern
Decorator design patternDecorator design pattern
Decorator design pattern
 
Boxing & unboxing
Boxing & unboxingBoxing & unboxing
Boxing & unboxing
 
Collections Api - Java
Collections Api - JavaCollections Api - Java
Collections Api - Java
 
Decorator Pattern
Decorator PatternDecorator Pattern
Decorator Pattern
 
Decorator Design Pattern
Decorator Design PatternDecorator Design Pattern
Decorator Design Pattern
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 

Destacado

Basic aircraft structure
Basic aircraft structureBasic aircraft structure
Basic aircraft structure
nyinyilay
 

Destacado (14)

Sustainability Drinks #20 – Will Veganism Save the World? - Lisa Hapke
Sustainability Drinks #20 – Will Veganism Save the World? - Lisa HapkeSustainability Drinks #20 – Will Veganism Save the World? - Lisa Hapke
Sustainability Drinks #20 – Will Veganism Save the World? - Lisa Hapke
 
Facade pattern
Facade patternFacade pattern
Facade pattern
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
Design Patterns - 03 Composite and Flyweight Pattern
Design Patterns - 03 Composite and Flyweight PatternDesign Patterns - 03 Composite and Flyweight Pattern
Design Patterns - 03 Composite and Flyweight Pattern
 
Mediator pattern
Mediator patternMediator pattern
Mediator pattern
 
Chassisand frame
Chassisand frameChassisand frame
Chassisand frame
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
31 interesting ways to use audio in your class
31 interesting ways to use audio in your class31 interesting ways to use audio in your class
31 interesting ways to use audio in your class
 
Creational Design Patterns
Creational Design PatternsCreational Design Patterns
Creational Design Patterns
 
Skin stringers-in-an-aircraft
Skin stringers-in-an-aircraftSkin stringers-in-an-aircraft
Skin stringers-in-an-aircraft
 
JETPACK Scenario Planning Module
JETPACK Scenario Planning ModuleJETPACK Scenario Planning Module
JETPACK Scenario Planning Module
 
best ppt on jet engines
best ppt on jet enginesbest ppt on jet engines
best ppt on jet engines
 
Subsonic and supersonic air intakes
Subsonic and supersonic air intakesSubsonic and supersonic air intakes
Subsonic and supersonic air intakes
 
Basic aircraft structure
Basic aircraft structureBasic aircraft structure
Basic aircraft structure
 

Similar a Flyweight pattern

ознакомления с модулем Entity api
ознакомления с модулем Entity apiознакомления с модулем Entity api
ознакомления с модулем Entity api
DrupalCamp Kyiv Рысь
 
Hibernate Training Session1
Hibernate Training Session1Hibernate Training Session1
Hibernate Training Session1
Asad Khan
 
Attached property
Attached propertyAttached property
Attached property
msarangam
 
Using ActiveObjects in Atlassian Plugins
Using ActiveObjects in Atlassian PluginsUsing ActiveObjects in Atlassian Plugins
Using ActiveObjects in Atlassian Plugins
Atlassian
 
Dependency property
Dependency propertyDependency property
Dependency property
msarangam
 
Introduction to XAML and its features
Introduction to XAML and its featuresIntroduction to XAML and its features
Introduction to XAML and its features
Abhishek Sur
 

Similar a Flyweight pattern (20)

ознакомления с модулем Entity api
ознакомления с модулем Entity apiознакомления с модулем Entity api
ознакомления с модулем Entity api
 
Introduction to Datastore
Introduction to DatastoreIntroduction to Datastore
Introduction to Datastore
 
Java Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreJava Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : Datastore
 
Aem best practices
Aem best practicesAem best practices
Aem best practices
 
Understanding the Entity API Module
Understanding the Entity API ModuleUnderstanding the Entity API Module
Understanding the Entity API Module
 
Data Binding in Silverlight
Data Binding in SilverlightData Binding in Silverlight
Data Binding in Silverlight
 
Hibernate Training Session1
Hibernate Training Session1Hibernate Training Session1
Hibernate Training Session1
 
Attached property
Attached propertyAttached property
Attached property
 
Introduction to JSX
Introduction to JSXIntroduction to JSX
Introduction to JSX
 
Flex3 Deep Dive Final
Flex3 Deep Dive FinalFlex3 Deep Dive Final
Flex3 Deep Dive Final
 
Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 
(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHP(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHP
 
Hello Android
Hello AndroidHello Android
Hello Android
 
Using ActiveObjects in Atlassian Plugins
Using ActiveObjects in Atlassian PluginsUsing ActiveObjects in Atlassian Plugins
Using ActiveObjects in Atlassian Plugins
 
The Magic of WPF & MVVM
The Magic of WPF & MVVMThe Magic of WPF & MVVM
The Magic of WPF & MVVM
 
Go f designpatterns 130116024923-phpapp02
Go f designpatterns 130116024923-phpapp02Go f designpatterns 130116024923-phpapp02
Go f designpatterns 130116024923-phpapp02
 
Dependency property
Dependency propertyDependency property
Dependency property
 
Introduction to XAML and its features
Introduction to XAML and its featuresIntroduction to XAML and its features
Introduction to XAML and its features
 
Hibernate
HibernateHibernate
Hibernate
 

Más de Shakil Ahmed (13)

B-tree & R-tree
B-tree & R-treeB-tree & R-tree
B-tree & R-tree
 
Advanced data structure
Advanced data structureAdvanced data structure
Advanced data structure
 
Command pattern
Command patternCommand pattern
Command pattern
 
Chain of responsibility
Chain of responsibilityChain of responsibility
Chain of responsibility
 
iOS 5
iOS 5iOS 5
iOS 5
 
Ios development
Ios developmentIos development
Ios development
 
Graph
GraphGraph
Graph
 
Lowest common ancestor
Lowest common ancestorLowest common ancestor
Lowest common ancestor
 
Segment tree
Segment treeSegment tree
Segment tree
 
Tree & bst
Tree & bstTree & bst
Tree & bst
 
Trie tree
Trie treeTrie tree
Trie tree
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Advanced Search Techniques
Advanced Search TechniquesAdvanced Search Techniques
Advanced Search Techniques
 

Último

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Último (20)

Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 

Flyweight pattern

  • 1. Prepared By : Hasnaeen Rizvi Rahman Astha School of Advanced Computing
  • 2. Use sharing to support large number of fine-grained objects efficiently.
  • 3. An application uses many objects.  A flyweight is a shared object that can be used in multiple contexts simultaneously.  It acts as an individual object in each context.  The key concept is the distinction between intrinsic and extrinsic state.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. An application uses a large number of objects.  Storage costs are high because of the sheer quantity of objects.  Most objects state can be made extrinsic.  Many groups of objects may be replaced by relatively few shared objects once extrinsic state is removed.  The application doesn’t depends on object identity.
  • 9.
  • 10.
  • 11. Flyweight (Glyph) • Declare an interface through which flyweights can receive and act on extrinsic state.  ConcreteFlyweight (Character) • Implements the Flyweight interface and adds storage for intrinsic state, if any.  UnsharedConcreteFlyweight (Row,Column) • Not all flyweight subclasses need to be shared.  Flyweight Factory • Creates and manages flyweight objects. • Ensures that flyweights are shared properly.  Client • Maintains a reference to flyweights • Computes or stores the extrinsic state of flyweight.
  • 12. Client passes extrinsic state to flyweight.  Client invokes FlyweightFactory to create Flyweight object.
  • 13. Flyweight may introduce run-time cost.  Storage savings are a function of several factors: • The reduction in the total number of instances that comes from sharing. • The amount of intrinsic state per object. • Whether extrinsic state is computed or stored.
  • 14. Removing extrinsic state.  Managing shared objects.
  • 15. Design an application which stores list of entities. • Entity: It has an ID, Name and an attribute. • Attribute: Attributes are composite data where each attribute is either a leaf or a composite. It has all child management operation suggested in composite pattern. A leaf attribute have a name and value. A Composite attribute have a name but no value. Attribute returns an XML having Name and Value node. The composite attribute returns the list of child attribute XML.
  • 16. Entity XML could be something like… <Entity> <ID>1</ID> <Name>Entity 1</Name> <Attribute> <Name>Entity Attribute</Name> <Children> <Attribute> <Name>OrgChart</Name> <Children> <Attribute> <Name>Type</Name> <Value>Corporation</Value> </Attribute> <Attribute> <Name>Country</Name> <Value>Bangladesh</Value> </Attribute> </Children> </Attribute> </Children> </Attribute> </Entity>
  • 17. Use Flyweight pattern to reduce memory usage for attributes.