Singleton mode:
Ensure that a class has only one instance and provides a global access point to it. ,
Structure:
Pay attention to the multi-threaded Singleton.
Metadata mode:
Enjoy yuan is flyweight, a professional term in sports. It is the most lightweight in boxing, wrestling, and weightlifting competitions. Porting this word to a software project is also used to represent a very small object, that is, a fine-grained object. The flyweight object can be understood as a shared object, that is, a shared fine-grained object. The metadata sharing mode enables efficient support for a large number of fine-grained objects by means of sharing. Its purpose is to save occupied space resources and improve system performance.
The metadata mode is used to share objects, that is, to use a shared pool to reduce memory allocation overhead. The sharing mode is usually used together with the factory mode. It contains multiple shared composite objects. Therefore, the sharing mode = Singleton mode + factory mode + merging mode, as shown in the structure 12-25.
The flyweightfactoiy metadata factory is responsible for creating and managing the metadata objects. It must ensure that the metadata objects can be shared by the system. When a client object requests a metadata object, the metadata factory needs to check whether there is a qualified metadata object in the system. If yes, the Yuan-sharing factory should provide the existing yuan-sharing object. if the system does not have an appropriate Yuan-sharing object, the Yuan-sharing factory should create a new suitable Yuan-sharing object. Flyweight is a superclass of all the specific Metadata classes. It specifies public interfaces or abstract classes to be implemented for these classes. Myflyweight1 and myflyweight2 are the interfaces defined by abstract metadata.