


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The flyweight pattern is a design pattern used to manage a large number of small objects efficiently. In this document, we explore an example of using the flyweight pattern to manage folder icons in a large organization, where the same graphical image is repeated for multiple instances but with different names and selected states. The efficiency issues with creating an icon object for each person and proposes a 'better' approach using a folderfactory to create and manage shared folder drawing classes.
Typology: Study notes
1 / 4
This page cannot be seen from the preview
Don't miss anything!



1
organization.each person in a anicon with a name under it forWe want to draw a small folder
for “not Selected.”one for “is Selected” and oneWe want two types of icons,
Lets code it. 3
created.one of each has beenadditional instances onceclass, but does not createunselected folder drawingeither the selected or theFolderFactory that returnsInstead, we’ll create a
return one or the other.both at the outset and thencase, we just create themSince this is such a simple
5
7
generate a very large number of small class instances to represent data.There are cases in programming where it seems that you need to
fundamentally the same except for a few parameters.you need to instantiate if you can recognize that the instances areSometimes you can greatly reduce the number of different classes that
be greatly reduced.them in as part of a method call, the number of separate instances canIf you can move those variables outside the class instance and pass
classes.The Flyweight design pattern provides an approach for handling such
It refers to the instance’s (^) intrinsic (^) data that makes the instance unique, and the (^) extrinsic (^) data which is passed in as arguments.
individual characters or icons on the screen.The Flyweight is appropriate for small, fine-grained classes like