C0mpy

flyweight

Jul 22nd, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. Flyweight
  2.  
  3. Minimizes memory use by sharing data with similarly typed objects
  4. When we need to make a more efficient use of memory
  5. An optimization pattern
  6. When we have a large number of similar, IMMUTABLE objects
  7.  
  8. Examples:
  9. - java.lang.String
  10. - java.lang.Integer#valueOf(int)
  11.  
  12. Design:
  13. - Utilizes other patterns inside of it
  14. - Uses factory to retrieve flyweight objects after they've been created
  15. - It has creation pattern inside structural pattern
  16. - It often manages the entire lifecycle of the object
  17.  
  18. https://i.imgur.com/4btnxPX.png
  19.  
  20. - Client is requesting the Flyweight object, although it doesn't know it's a flyweight
  21. - Client requests it from the FlyweightFactory
  22. - Factory returns the cached object or it creates a new instance of the flyweight
  23. - ConcreteFlyweight is what gets returned to the Client
Add Comment
Please, Sign In to add comment