1 / 18

Katie C. O’Shea Dennis T. Tillman 11 February 2K2

Flyweight. Katie C. O’Shea Dennis T. Tillman 11 February 2K2. Flyweight. Patterns Presentation . Recap Agenda. Flyweight. Flyweight. Description. Definition. Flyweight(fli-wat) Something that is particularly small, light, or inconsequential. . Comp Sci: Pattern

jenski
Download Presentation

Katie C. O’Shea Dennis T. Tillman 11 February 2K2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Flyweight Katie C. O’Shea Dennis T. Tillman 11 February 2K2

  2. Flyweight Patterns Presentation Recap Agenda Flyweight

  3. Flyweight Description Definition • Flyweight(fli-wat) • Something that is particularly small, light, or inconsequential. • Comp Sci: Pattern • Structural pattern used to support a large number of small objectsefficiently • Flyweight factors the common properties of multiple instances of a class into a single object, saving space and maintenance of duplicate instances.

  4. Flyweight Description Design Considerations Pattern for managing the use of a discreet set of objects. Operations • throughout a system • singularly, independently • in parallel contexts Organization • Reduce costs when sheer quantities of objects require increased storage • Deal with intrinsic and external states independently • Replace groups with shared objects • Application must not rely on object identity

  5. CD: a CD: b CD: c <<extrinsic state>> year <<extrinsic state>> title <<extrinsic state>> year <<extrinsic state>> title <<extrinsic state>> year <<extrinsic state>> title Nirvana: artistFlyweight Sinatra: artistFlyweight :artistFactory <<intrinsic state>> artistName <<intrinsic state>> artistName Flyweight Implementation Portfolio Application

  6. Flyweight Implementation Document Processing Pattern for managing the use of a small set of objects. • throughout a system

  7. Flyweight Implementation Document Processing Pattern for managing the use of a small set of objects. • throughout a system • In multiple contexts • throughout a system • In multiple contexts

  8. Structure Row client supports context dependent information — tells children where they should draw themselves by passing location information Glyph Row Draw(Context) Intersection(Point, Context) Draw(Context) Intersection(Point, Context) Column Draw(Context) Intersection(Point, Context) Character Draw(Context) Intersection(Point, Context) Flyweight Word Processor Example • GLYPH, the abstract class for graphical objects Flyweight storing a single character — doesn’t need to know location or font char c Supplies context dependent information that the Flyweight needs to draw itself

  9. Structure Flyweight Word Processor Example Row client supports context dependent information — tells children where they should draw themselves by passing location information Row Draw(Context) Intersection(Point, Context) • GLYPH, the abstract class for graphical objects Character Flyweight storing a single character — doesn’t need to know location or font Glyph Draw(Context) Intersection(Point, Context) Draw(Context) Intersection(Point, Context) char c Column Supplies context dependent information that the Flyweight needs to draw itself Draw(Context) Intersection(Point, Context)

  10. Flyweight Structure Class Diagram

  11. Flyweight Structure Class Diagram • Maintains references to Flyweight • Supplies context dependent information that the Flyweight needs to draw itself • The Flyweight is the set of intrinsic information that a set of objects share in common. It is abstract. • For subclasses that do not need to be shared • Implements Flyweight interface • Store intrinsic state • (must be) shareable • Creates, manages Flyweights • Dispenses when requested • Ensures sharing • (checks existence)

  12. Flyweight Structure Object Diagram page 198

  13. Flyweight Efficiency Benefits and Consequences + - If the size of the set of objects used repeatedly is substantially smaller than the number of times the object is logically used, there may be an opportunity for a considerable cost benefit • Overhead to track state • Transfer • Search • computation • When Not To Use Flyweight: • If the extrinsic properties have a large amount of state information that would need passed to the flyweight (overhead) • Need to be able to be distinguished shared from non-shared objects • When To Use Flyweight: • There is a need for many objects to exist that share some intrinsic, unchanging information • Objects can be used in multiple contexts simultaneously • Acceptable that flyweight acts as an independent object in each instance

  14. A document uses about 100 character objects (the ASII set) 100 Chars shared in 8,000 char document 100 Chars shared in 200,000 char document Flyweight Efficiency Benefits and Consequences • f(g): • reduction in number of instances • amount of intrinsic state • state per object • computation • storage Savings Number of Objects Shared

  15. Flyweight Implementation Applications • Celebrity portfolio, CD Database • Word processing • GUI (skins, look and feel) • Server connection pool

  16. Flyweight Implementation Code Example Balls and Strategies (java) http://exciton.cs.rice.edu/JavaResources/DesignPatterns/FlyweightDocs/example/Flyweight.zip

  17. Composite State Strategy Flyweight Implementation Related Patterns Flyweight

  18. Flyweight Patterns Presentations Catalogued patterns - Recap

More Related