This article mainly introduces the metadata sharing mode in the php design mode. if you are interested, refer to it.
I. intentionUse sharing technology to effectively support a large number of fine-grained objects
The metadata mode changes the storage overhead of objects.
II. structure of the metadata mode
III. primary roles in the metadata modeAbstract Flyweight role:This role is a superclass of all the specific metadata classes, and defines the p
/release + 49 tfWt /u5ss/queues/nS1M2s0ru49tfWt/uz9s/wyrgjr4z/queues/ztcS5ss/queues/Qxc + queues/OjrNTau + queues + blocks = "http://www.2cto.com/uploadfile/2014/0209/20140209112907783.png" alt = "\"> physical on: structure:Applicability: the Flyweight mode has strict application requirements. Its effectiveness depends largely on how it is used and where it is used. You can use the Flyweight mode when "All
Design Patterns
----Flyweight (
Henry Yuan
)
Mode
GOF
:The use of sharing technology to effectively support a large number of fine-grained objects.
explain the concept:That is, if you have more than one object in a system, it's OK to share only one copy, without having to instantiate each object. For example (refer to the example in Gof book) a text system, each letter to set an object, then the large lowercase letter is 52, then you need to defi
the object is displayed.
role: the use of shared technology to effectively support a large number of fine-grained objects.
Internal state intrinsic and external state extrinsic:
1 in flyweight mode, the most important thing is to decompose the object into intrinsic and extrinsic two parts.
2 internal state: The shared part that is inside the object of the element and does not change with the environment, can be called the internal state of the ob
Definition
The sharing technology is used to effectively support a large number of fine-grained objects. The system only uses a small number of objects. These objects are similar, the state changes are small, and the usage of objects increases.
The UML class diagram is as follows:
The relationship between classes and objects:
1. flyweight (Abstract lightweight class): declares an interface that can accept external parameters (states) an
1. Explanation of the definition of the 1.1 yuan mode in the shared element mode (Structural)
The sharing technology is used to effectively support a large number of fine-grained objects.Share: Share the internal statusKey points of the 1.2 yuan Sharing Model
The focus is on changing and changing the separation.Divides the state of an object into internal and external States. The internal State remains unchanged and the external state changes.The internal state is managed in the object through t
Reprint Please specify source: http://blog.csdn.net/l1028386804/article/details/45568799I. OverviewUse shared technology to effectively support a large number of fine-grained objects.Second, applicabilityUse flyweight mode when all of the following conditions are in place:1. An application uses a large number of objects.2. Due to the use of a large number of objects, resulting in a large storage overhead.3. Most of the state of an object can become an
role:This role must maintain a reference to all the metadata objects. This role needs to store the external status of all the meta objects on its own.
Sample Code:
The internal state is saved by the intrinsicstate. After an object is created, all the internal states cannot be changed.
The external status is set through operation, which is called and changed by the client as needed.
In the following code, three object categories are applied, but only two object categories are created. This is th
Flyweight is the most lightweight in boxing, that is, "Fly magnitude", which is translated by some authors as "Yu magnitude ". Here, the "share mode" is used to better reflect the intention of the mode.
The metadata mode supports a large number of fine-grained objects efficiently in a shared manner. The key to enabling shared object sharing is to differentiate the Internal State and External State ). The internal state is stored inside the object and
Intent:Use sharing technology to effectively support a large number of fine-grained objectsApplicable:An application uses a large number of objects.A large amount of storage overhead is caused by the use of a large number of objects.Most States of objects can be changed to external states.If you delete the external state of an object, you can replace multiple groups of objects with fewer shared objects.UMLResolution:The flywweight mode is widely used when shared objects are frequently used.// Te
// Flyweight. cpp: defines the entry point of the console application.//
# Include "stdafx. H"# Include # Include # Include
Using namespace STD;
Typedef string state;
Class flyweight{Public:State getintrinsicstate (){Return m_state;}
Virtual void operation (State extrinsic) = 0;
Protected:Flyweight (const State S): m_state (s){}
PRIVATE:State m_state;
};
Class concreteflyweight: Public
-factory, responsible for creating and managing the Sharing object/// Public classFlyweightfactory {//It is best to use the generic dictionary//Public dictionary PublicHashtable flyweights =NewHashtable (); Publicflyweightfactory () {flyweights. ADD ("A",NewConcreteflyweight ("A")); Flyweights. ADD ("B",NewConcreteflyweight ("B")); Flyweights. ADD ("C",NewConcreteflyweight ("C")); } PublicFlyweight Getflyweight (stringkey) {//better to achieve the following//
// Considering such a word processing software, the object to be processed may have a single character, a paragraph consisting of characters and the entire document. According to the object-oriented design idea and the composite mode, whether it is a character or a paragraph, a document should be viewed as a single object. Here, only a single character is taken into account, and paragraphs, documents, and other objects are not considered.# Endregion
# Region usage// Effect and key points// 1. O
represent shared objects.
This application scenario is available in recent projects. For example, some file icons can be used repeatedly and put into the cache, in the future, each call can be directly read from the cache.
Mode Structure
FlyweightfactortyThe factory method that provides shared objects contains a clustering object. Generally, hashmap is used. Generally, this factory class is created in singleton mode.
1 class FlyweightFactory{ 2 private HashMap map = new HashMap
Http://www.35java.com/zhibo/forum.php? MoD = viewthread tid = 276 extra = Page % 3d2
InGof booksThe purpose of Flyweight is to use the sharing technology so that some fine-grained objects can be shared.
The description of Flyweight in the Oxford dictionary is "boxer of the lightest class ". Is it a lightweight boxer? In fact, this part should be interpreted as "thelightestclass". In a lightweight c
-sample mode to create the enjoyment of meta-objects5, the enjoyment meta-object can be pre-set in the enjoy meta-factory, you can also create a collection, each time you create an object, see if the object exists, does not exist to addSecond, the mode code1. Create a meta-interface Package Flyweight.patten; // enjoy meta interface Public Interface FlyWeight { publicvoid opertion ();}2. Create a specific class of enjoyment Package Flyweight.patte
(Flyweight) mode: The sharing of technology to effectively support a large number of fine-grained objects.In Shanhong's "Java and Mode", the model is divided into simple and complex modes, the compound-mode is not to be shared, and the key to share is to distinguish the intrinsic state (the Internal state) and the outer Yun (External). These two "Yun" translation is too difficult to understand, I am not saying that translation is not good, may be my a
definition: the use of shared technology to effectively support a large number of fine-grained objects.
Type: Object-structured pattern
class Diagram:
structure of the flyweight pattern
abstract Flyweight Role: describes an interface through which Flyweight can be accepted and acting on an external state. The concreteflyweight role: implements the
First, the flyweight mode definition:
The use of sharing technology to effectively support a large number of fine-grained objects.
Second, the model explanation
That is, if you have more than one object in a system, it's OK to share only one copy, without having to instantiate each object. In flyweight mode, factory patterns often occur in flyweight mode becau
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 ca
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.