A brief introduction to the mode of Brief (Introduction)
(Flyweight pattern), the use of shared technology to effectively support a large number of fine-grained objects.
Use sharing to support large numbers of fine-grained objects.
The privilege pattern avoids the overhead of a large number of very similar classes. In programming, it is sometimes necessary to generate a large number of fine-grained class instances to represent data. If these instances are found to be identical except for a few of the parameters, the number of classes that need to be instantiated can sometimes be reduced by a large amount. If you can move these parameters outside the class instance and pass them in when the method is called, you can drastically reduce the number of individual instances by sharing.
The internal state and external state of the Privilege object:
An internal state, a shared part that is within the object of the element and that does not change with the environment.
An external state that changes with the environment and cannot be shared.
Ii. issues addressed (What to Solve)
If an application uses a large number of objects, and a large number of these objects cause a large storage overhead, consider using the pattern of privileges.
When most of the state of an object is an external state, if you delete the external state of an object, you can replace many groups of objects with a relatively small share object, and you can also consider using the pattern of privileges.
Analysis of the mode of enjoying meta-element
1. Pattern structure of the element
Flyweightfactory class: The Henry Factory, which is used to create and manage flyweight objects. If the requested flyweight object exists, how to return an object that already exists. Otherwise, a new object is created to return.
Flyweight class: The abstract class, through which flyweight can accept and interact with the external state.
Unsharedconcreteflyweight class: Flyweight subclasses that do not need to be shared. The flyweight interface does not force sharing.
Concreteflyweight class: Implement the Meta abstract class to add storage space for the internal state.