Flyweight Pattern ‘Use sharing to support large numbers of fine-grained objects efficiently.’   Derek Weeks Melbourne Patt...
Intent <ul><li>Use sharing to support large numbers of fine-grained objects efficiently.  </li></ul>
Problem <ul><li>Want to design objects at a granular level </li></ul><ul><li>But... </li></ul><ul><li>Don’t want your app ...
Example <ul><li>System for batch processing of orders (online groceries) </li></ul><ul><li>Identical items appear in many ...
Flyweight Class Diagram
Implementation of Example
When to use flyweight <ul><li>When  all  of the following are true </li></ul><ul><ul><li>Large number of objects used </li...
Discussion <ul><li>Often combined with Composite pattern </li></ul><ul><li>Who has used this before? </li></ul><ul><li>Any...
Upcoming SlideShare
Loading in …5
×

Flyweight Pattern Melbourne Patterns Group 4 April 2007

1,270 views
1,202 views

Published on

Flyweight Pattern Melbourne Patterns Group

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,270
On SlideShare
0
From Embeds
0
Number of Embeds
62
Actions
Shares
0
Downloads
53
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Flyweight Pattern Melbourne Patterns Group 4 April 2007

  1. 1. Flyweight Pattern ‘Use sharing to support large numbers of fine-grained objects efficiently.’ Derek Weeks Melbourne Patterns Group Wednesday 4 April 2007 www.linkedin.com/in/derekweeks
  2. 2. Intent <ul><li>Use sharing to support large numbers of fine-grained objects efficiently. </li></ul>
  3. 3. Problem <ul><li>Want to design objects at a granular level </li></ul><ul><li>But... </li></ul><ul><li>Don’t want your app to run like a (slow) dog </li></ul>
  4. 4. Example <ul><li>System for batch processing of orders (online groceries) </li></ul><ul><li>Identical items appear in many orders </li></ul><ul><li>Want to represent items as objects (why?) </li></ul><ul><li>Each item has state </li></ul><ul><ul><li>Price </li></ul></ul><ul><ul><li>Size </li></ul></ul><ul><ul><li>Current storage area </li></ul></ul><ul><ul><li>Weight </li></ul></ul><ul><ul><li>Which order it belongs to </li></ul></ul><ul><li>To share item objects, we need to separate the intrinsic state from the extrinsic state </li></ul><ul><li>What methods do item objects expose? </li></ul>
  5. 5. Flyweight Class Diagram
  6. 6. Implementation of Example
  7. 7. When to use flyweight <ul><li>When all of the following are true </li></ul><ul><ul><li>Large number of objects used </li></ul></ul><ul><ul><li>Storage costs are high </li></ul></ul><ul><ul><li>Most state can be made extrinsic </li></ul></ul><ul><ul><li>High proportion of objects shareable </li></ul></ul><ul><ul><li>No requirement for object identity </li></ul></ul>
  8. 8. Discussion <ul><li>Often combined with Composite pattern </li></ul><ul><li>Who has used this before? </li></ul><ul><li>Any traps to watch out for? </li></ul><ul><li>Is performance the only benefit? </li></ul>

×