1. Intention
Share mode: Use the sharing technology to effectively support a large number of fine-grained objects
2. Core Ideas
The metadata mode efficiently supports a large number of fine-grained objects in a shared manner. The key to the sharing mode is to distinguish between the internal and external states.
The internal status is stored in the shared element and will not change with the environment. The external state changes with the change of the environment. The external status cannot affect the internal status. They are independent of each other.
The States that can be shared and those that cannot be shared are separated from the conventional classes to remove the States that cannot be shared from the classes.
The client cannot directly create shared objects, but should use a factory object to create shared objects. The metadata mode greatly reduces the number of objects in the memory.
3. Advantages and Disadvantages
Good:
(1) Use the sharing technology to effectively support a large number of fine-grained objects (for C ++, it is to share a memory block, and the Object Pointer Points to the same place ).
(2) If an applicationProgramA large number of objects are used, and these objects cause a large storage overhead.
(3) In addition, most states of objects can be external States. If you delete the external States of objects, you can replace multiple groups of objects with fewer shared objects. In this case, you can consider using the shared object.
4. UML diagram