Design Pattern series-single-instance mode meta Mode

Source: Internet
Author: User

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.

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.