Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the (GoF) Flyweight a structural (and not a creational) design pattern?

To my understanding, the flyweight design pattern is not so different from the factory or singleton design patterns.

It is just a factory that produces immutable (and pooled) objects. It is just a singleton that provides one instance per type (of the managed objects), instead of a global single instance.

Factory and singleton are creational patterns, so why should the flyweight be considered a structural pattern?

like image 698
Nicola Ferraro Avatar asked Jun 09 '15 23:06

Nicola Ferraro


1 Answers

The essence of the Flyweight pattern is not creation of objects but sharing of them. The pattern states that the objects to be shared are usually held in some external data structure but does not specify how those data structures are created or represented.

What makes the pattern structural is the use of factory-like class to obtain the flyweights. This imposes a static structure on the design.

like image 106
iluwatar Avatar answered Sep 27 '22 18:09

iluwatar