SlideShare a Scribd company logo
2
Most read
4
Most read
11
Most read
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.
Flyweight pattern
Flyweight pattern
Flyweight pattern
Flyweight pattern
   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 pattern
Flyweight pattern
   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.

More Related Content

PPTX
Facade Design Pattern
PPTX
Design Pattern - Singleton Pattern
PPT
Facade pattern
PDF
Understanding react hooks
PPT
Builder pattern
PPTX
Creational pattern
PPTX
Adapter Design Pattern
PPT
Composite pattern
Facade Design Pattern
Design Pattern - Singleton Pattern
Facade pattern
Understanding react hooks
Builder pattern
Creational pattern
Adapter Design Pattern
Composite pattern

What's hot (20)

PPTX
Adapter Design Pattern
PPT
Software Design Patterns
PPTX
Flyweight Pattern
PPT
Proxy pattern
PPTX
Proxy Design Pattern
PPT
Mvc architecture
PPTX
PPTX
Facade pattern presentation(.pptx)
PPT
Bridge Design Pattern
PDF
PPT
Adapter pattern
PDF
Java Design Patterns Tutorial | Edureka
PPS
Java Hibernate Programming with Architecture Diagram and Example
PPTX
Angular interview questions
PDF
Design patterns
PPT
Core java
PDF
Spring MVC Framework
PPTX
React hooks
PPT
Composite Design Pattern
PPTX
Spring boot
Adapter Design Pattern
Software Design Patterns
Flyweight Pattern
Proxy pattern
Proxy Design Pattern
Mvc architecture
Facade pattern presentation(.pptx)
Bridge Design Pattern
Adapter pattern
Java Design Patterns Tutorial | Edureka
Java Hibernate Programming with Architecture Diagram and Example
Angular interview questions
Design patterns
Core java
Spring MVC Framework
React hooks
Composite Design Pattern
Spring boot
Ad

Viewers also liked (15)

PDF
Sustainability Drinks #20 – Will Veganism Save the World? - Lisa Hapke
PPT
Facade pattern
PPT
Algorithm
PPTX
Design Patterns - 03 Composite and Flyweight Pattern
PPT
Mediator pattern
PPTX
Chassisand frame
PPT
Observer pattern
PPT
31 interesting ways to use audio in your class
PDF
Creational Design Patterns
PPTX
Skin stringers-in-an-aircraft
PDF
JETPACK Scenario Planning Module
PPT
Prototype pattern
PPTX
best ppt on jet engines
PDF
Subsonic and supersonic air intakes
PPT
Basic aircraft structure
Sustainability Drinks #20 – Will Veganism Save the World? - Lisa Hapke
Facade pattern
Algorithm
Design Patterns - 03 Composite and Flyweight Pattern
Mediator pattern
Chassisand frame
Observer pattern
31 interesting ways to use audio in your class
Creational Design Patterns
Skin stringers-in-an-aircraft
JETPACK Scenario Planning Module
Prototype pattern
best ppt on jet engines
Subsonic and supersonic air intakes
Basic aircraft structure
Ad

Similar to Flyweight pattern (20)

PPTX
How to Draw an Effective ER diagram
PPT
Hive Object Model
PDF
Flyweight Pattern in Python: Optimizing Memory Usage
PPTX
OOAD.pptx
PDF
ERD with complete knowledge
PPTX
MVP Cloud OS Week: 9 Sept, Track 1 Data Liberty
PPTX
MVP Cloud OS Week Track 1 9 Sept: Data liberty
KEY
Spring AOP
PDF
Unit 2-Data Modeling.pdf
ODP
Objects arent records with byte codes on the side
PPTX
dbms ppt parul university dbms course for
PPTX
unified modelling language(UML) diagrams
PPT
Ooad Uml
ODP
BIS08 Application Development - II
PPTX
Outlier and fraud detection using Hadoop
PPTX
Creating a Single View Part 2: Loading Disparate Source Data and Creating a S...
PPTX
Geographic Information systems
PPTX
Spatial Data Models
PPTX
Geographic Information System unit 2
PPTX
Silicon valley nosql meetup april 2012
How to Draw an Effective ER diagram
Hive Object Model
Flyweight Pattern in Python: Optimizing Memory Usage
OOAD.pptx
ERD with complete knowledge
MVP Cloud OS Week: 9 Sept, Track 1 Data Liberty
MVP Cloud OS Week Track 1 9 Sept: Data liberty
Spring AOP
Unit 2-Data Modeling.pdf
Objects arent records with byte codes on the side
dbms ppt parul university dbms course for
unified modelling language(UML) diagrams
Ooad Uml
BIS08 Application Development - II
Outlier and fraud detection using Hadoop
Creating a Single View Part 2: Loading Disparate Source Data and Creating a S...
Geographic Information systems
Spatial Data Models
Geographic Information System unit 2
Silicon valley nosql meetup april 2012

More from Shakil Ahmed (14)

PPT
B-tree & R-tree
PPTX
Advanced data structure
PPT
Command pattern
PPT
Chain of responsibility
PPT
Bridge pattern
PPT
PPT
Ios development
PPT
PPT
Lowest common ancestor
PPT
Segment tree
PPT
Tree & bst
PPT
Trie tree
PPT
Dynamic programming
PPT
Advanced Search Techniques
B-tree & R-tree
Advanced data structure
Command pattern
Chain of responsibility
Bridge pattern
Ios development
Lowest common ancestor
Segment tree
Tree & bst
Trie tree
Dynamic programming
Advanced Search Techniques

Recently uploaded (20)

PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
Business Ethics Teaching Materials for college
PPTX
Institutional Correction lecture only . . .
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
01-Introduction-to-Information-Management.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Complications of Minimal Access Surgery at WLH
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Pre independence Education in Inndia.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Business Ethics Teaching Materials for college
Institutional Correction lecture only . . .
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
102 student loan defaulters named and shamed – Is someone you know on the list?
O7-L3 Supply Chain Operations - ICLT Program
01-Introduction-to-Information-Management.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Module 4: Burden of Disease Tutorial Slides S2 2025
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Final Presentation General Medicine 03-08-2024.pptx
Week 4 Term 3 Study Techniques revisited.pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Complications of Minimal Access Surgery at WLH
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Pre independence Education in Inndia.pdf
Microbial diseases, their pathogenesis and prophylaxis

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