Why is (GoF) Flyweight a structural (not crafted) design pattern?

As far as I understand, the fly design pattern is not that much different from the factory or singleton design patterns.

It's just a factory that creates immutable (and merged) objects. It's just a singleton that provides one instance for each type (managed objects) instead of a globally separate instance.

Factory and singleton are creation patterns, so why are flies considered structural?

+3


source to share


2 answers


The Flyweight pattern is not about creating objects, but sharing them. The template states that objects to be shared are usually stored in some external data structure, but do not define how these data structures are created or presented.



What makes the pattern structured is to use a factory-like class to get a fly out. This imposes a static structure on the design.

+4


source


The garbage pattern does not create any objects. It is used to store data that is shared between multiple objects. You can compare its use with static methods / variables in a class. Instead of defining them for each instance, you can use a global instance that supports that method or data to reduce the memory footprint of your application.



Suppose you are parsing a large data file using multiple parsers, instead of having each parser read the complete data file, you could use the flyweight pattern to store one instance of the data file that each parser can access.

+1


source







All Articles