Enjoy meta mode flyweight
The combined mode solves how the object is processed when it is tree-shaped. When the system needs to use a lot of duplicate objects, and these objects to consume a large amount of resources, you need to use the enjoy meta-mode to solve.
Singleton mode, a class has only one unique object. That is, no matter how many times new, just want to create an object of this class, if not in singleton mode, no new will create an object, this is necessary for the system to use a large number of duplicate objects, and these objects need to consume a lot of resources, it is not cost-effective, then need to use the enjoy meta-mode.
Database connection pooling is a typical application of the enjoy meta-mode.
The principle of the realization of the META mode
Schematic diagram of the realization of the meta-mode
Pros and cons of the enjoy meta model
Benefits of the meta-mode: Reduce the number of objects, save memory space.
The disadvantage of the enjoy meta-mode: Maintaining shared objects requires additional overhead (using a thread to maintain garbage collection).
The essence of the enjoy meta model: separation and sharing.
Design mode (10) Enjoy meta mode (Flyweight)-Structural type