Flyweight%20An%20Object%20Structural%20Design%20Pattern - PowerPoint PPT Presentation

About This Presentation
Title:

Flyweight%20An%20Object%20Structural%20Design%20Pattern

Description:

Simply put, a method for storing a small number of complex objects that are used ... Computing extrinsic state instead of storing it. Related Patterns ... – PowerPoint PPT presentation

Number of Views:78
Avg rating:3.0/5.0
Slides: 10
Provided by: johnmarci
Learn more at: http://www.cs.rpi.edu
Category:

less

Transcript and Presenter's Notes

Title: Flyweight%20An%20Object%20Structural%20Design%20Pattern


1
FlyweightAn Object Structural Design Pattern
  • JM Imbrescia

2
Intent
  • Use Sharing to support large numbers of
    fine-grained objects efficiently.
  • Simply put, a method for storing a small number
    of complex objects that are used repeatedly.

3
Motivation(Why use the Flyweight Pattern?)
  • If you have an application that would benefit
    from using objects throughout your design.
  • Document Editors
  • 50 Decks of cards

4
Definitions
  • Flyweight
  • A shared object that can be used in multiple
    contexts simultaneously.
  • Intrinsic
  • State information that is independent of the
    flyweights context. Shareable Information.
  • Extrinsic
  • State information that depends on the context of
    the flyweight and cannot be shared.

5
Applicability
  • Use the Flyweight when all of the following are
    true
  • Application has a large number of objects.
  • Storage costs are high because of the large
    quantity of objects.
  • Most object state can be made extrinsic.
  • Many groups of objects may be replaced by
    relatively few once you remove their extrinsic
    state.
  • The application doesnt depend on object
    identity.

6
Participants
  • Flyweight
  • ConcreteFlyweight
  • UnsharedConcreeteFlyweight
  • FlyweightFactory
  • Client

7
Image from the book thanks to http//www.cs.jhu.e
du/scott/oos/lectures/PatternDiagrams
8
Consequences
  • Flyweights introduce runtime costs, these costs
    need to be offset by storage space savings.
    Savings come from
  • Fewer total instances due to sharing.
  • Increasing intrinsic space per object.
  • Computing extrinsic state instead of storing it.

9
Related Patterns
  • Often combined with the Composite pattern.
  • State and Strategy objects are often implemented
    as flyweights.
Write a Comment
User Comments (0)
About PowerShow.com