(Structural mode) flyweight-Metadata Mode

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.