The flyweight design patterns offer great efficiency and improved processing when dealing with a large number of similar objects. The pattern uses sharing of identical object components. Consider programming a video game that has thousands of tile objects that are used to build architectural structures. The tile objects will likely only have a color attribute. So repeating the Tiles tile = new Tiles("beige") line of code 1,000 times is not efficient, especially since all of the objects will contain the same attribute value. The flyweight design pattern addresses this issue by permitting the reference of numerous same-type objects that have the same state.
Soaring with the flyweight design pattern
Use case
We will...