Flyweight mode (Hengyuan mode)

Source: Internet
Author: User
that should be the best understanding of a design pattern. The principle of object-oriented language is that everything is an object, but if you really use it, sometimes the number of objects may seem very large, for example, word processing software, if each text as an object, thousands of words, the number of objects is thousands of, no doubt consumes memory, then we still want to "disagree", Find out what these object groups have in common, design a meta-class, encapsulate the classes that can be shared, and, in addition, some features that depend on the application (context), are not shareable, This is the flyweight of two important concepts-internal state intrinsic and external state extrinsic. White point, is to pinch a primitive model, and then with different circumstances and environment, and then produce each characteristic of the concrete model, it is obvious that here need to produce different new objects, so flyweight pattern often appear Factory mode. The internal state of the Flyweight is used for sharing, and Flyweight factory is responsible for maintaining an object that has a Flyweight pool (pattern pools) to hold the internal state. Flyweight mode is a mode to improve the efficiency and performance of the program, which will greatly speed up the operation of the program.  There are many applications: for example, if you want to read a series of strings from a database, many of which are duplicates, then we can store these strings in the flyweight pool. Very simple, detailed code see: http://www.cnblogs.com/cxjchen/p/3194379.html

Flyweight mode (Hengyuan mode)

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.