SlideShare uma empresa 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.

Mais conteúdo relacionado

Mais procurados

The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern PresentationJAINIK PATEL
 
Observer design pattern
Observer design patternObserver design pattern
Observer design patternSara Torkey
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1Shahzad
 
Observer Software Design Pattern
Observer Software Design Pattern Observer Software Design Pattern
Observer Software Design Pattern Nirthika Rajendran
 
Java Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | EdurekaJava Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | EdurekaEdureka!
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design patternMindfire Solutions
 
Decorator Design Pattern
Decorator Design PatternDecorator Design Pattern
Decorator Design PatternAdeel Riaz
 
Design Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternDesign Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternMudasir Qazi
 
Design Pattern - Singleton Pattern
Design Pattern - Singleton PatternDesign Pattern - Singleton Pattern
Design Pattern - Singleton PatternMudasir Qazi
 
Hibernate tutorial for beginners
Hibernate tutorial for beginnersHibernate tutorial for beginners
Hibernate tutorial for beginnersRahul Jain
 

Mais procurados (20)

Adapter pattern
Adapter patternAdapter pattern
Adapter pattern
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern Presentation
 
Builder design pattern
Builder design patternBuilder design pattern
Builder design pattern
 
Proxy Design Pattern
Proxy Design PatternProxy Design Pattern
Proxy Design Pattern
 
Design pattern
Design patternDesign pattern
Design pattern
 
Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
 
Composite design pattern
Composite design patternComposite design pattern
Composite design pattern
 
Observer Software Design Pattern
Observer Software Design Pattern Observer Software Design Pattern
Observer Software Design Pattern
 
Java Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | EdurekaJava Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | Edureka
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
 
Prototype pattern
Prototype patternPrototype pattern
Prototype pattern
 
Design pattern-presentation
Design pattern-presentationDesign pattern-presentation
Design pattern-presentation
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Decorator Design Pattern
Decorator Design PatternDecorator Design Pattern
Decorator Design Pattern
 
Bridge Design Pattern
Bridge Design PatternBridge Design Pattern
Bridge Design Pattern
 
Design Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternDesign Pattern - Factory Method Pattern
Design Pattern - Factory Method Pattern
 
Design Pattern - Singleton Pattern
Design Pattern - Singleton PatternDesign Pattern - Singleton Pattern
Design Pattern - Singleton Pattern
 
Hibernate tutorial for beginners
Hibernate tutorial for beginnersHibernate tutorial for beginners
Hibernate tutorial for beginners
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 

Destaque

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 HapkeGreenBuzz Berlin
 
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 Patterneprafulla
 
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 classmrholdsworth
 
Skin stringers-in-an-aircraft
Skin stringers-in-an-aircraftSkin stringers-in-an-aircraft
Skin stringers-in-an-aircraftsubhan90
 
JETPACK Scenario Planning Module
JETPACK Scenario Planning ModuleJETPACK Scenario Planning Module
JETPACK Scenario Planning ModuleCaleb Sexton
 
best ppt on jet engines
best ppt on jet enginesbest ppt on jet engines
best ppt on jet enginesDeepak Kumar
 
Subsonic and supersonic air intakes
Subsonic and supersonic air intakesSubsonic and supersonic air intakes
Subsonic and supersonic air intakesSanjay Singh
 
Basic aircraft structure
Basic aircraft structureBasic aircraft structure
Basic aircraft structurenyinyilay
 

Destaque (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
 

Semelhante a Flyweight pattern

ознакомления с модулем Entity api
ознакомления с модулем Entity apiознакомления с модулем Entity api
ознакомления с модулем Entity apiDrupalCamp Kyiv Рысь
 
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] : DatastoreIMC Institute
 
Understanding the Entity API Module
Understanding the Entity API ModuleUnderstanding the Entity API Module
Understanding the Entity API ModuleSergiu Savva
 
Data Binding in Silverlight
Data Binding in SilverlightData Binding in Silverlight
Data Binding in SilverlightBoulos Dib
 
Hibernate Training Session1
Hibernate Training Session1Hibernate Training Session1
Hibernate Training Session1Asad Khan
 
Attached property
Attached propertyAttached property
Attached propertymsarangam
 
Introduction to JSX
Introduction to JSXIntroduction to JSX
Introduction to JSXMicah Wood
 
Flex3 Deep Dive Final
Flex3 Deep Dive FinalFlex3 Deep Dive Final
Flex3 Deep Dive FinalRJ Owen
 
Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1Salesforce Developers
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate pptAneega
 
(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 PHPRick Ogden
 
Using ActiveObjects in Atlassian Plugins
Using ActiveObjects in Atlassian PluginsUsing ActiveObjects in Atlassian Plugins
Using ActiveObjects in Atlassian PluginsAtlassian
 
The Magic of WPF & MVVM
The Magic of WPF & MVVMThe Magic of WPF & MVVM
The Magic of WPF & MVVMAbhishek Sur
 
Dependency property
Dependency propertyDependency property
Dependency propertymsarangam
 
Introduction to XAML and its features
Introduction to XAML and its featuresIntroduction to XAML and its features
Introduction to XAML and its featuresAbhishek Sur
 

Semelhante 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
 

Mais de Shakil Ahmed

Mais 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

Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 

Último (20)

YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 

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.