1. What is the prototype model
The prototype pattern belongs to the creation mode of the object. The prototype pattern allows you to create a new instance by copying an existing instance.The point of this pattern is that the clie
The prototype pattern is actually similar to the factory pattern, which is used to create objects, except that they are different from the implementation of the factory pattern. The prototype pattern is to create a
address information in the registration information, the address is a separate class, copy the registration information at the same time to copy the registration information refers to the address object, so that the registration information object copy refers to a copy of the original nationality object. That is, let the address class also implement prototype mode, implement Cloneable interface.Geology Category:
1234567891011121314151617
to the public type.Prototype mode is a relatively simple pattern, and it is very easy to understand, implement an interface, rewrite a method that completes the prototype mode. In practical applications, prototype patterns rarely appear alone. Often mixed with other patterns, his prototype class
Prototype of Design Pattern
The object created by the factory method is a new object, and its attributes are generally default.
What I understand is that the prototype operation method creates a clone body, which can be considered as two steps: 1. creates an object. 2. copy the attributes of the created object as the c
Prototype mode of thinking: An object as a prototype, copy it, clone, and produce a new object similar to the original object.By the visible, a prototype class, only need to implement Cloneable interface, replication Clone method.In Java, there are two kinds of clones: the depth of the point, specific to see HTTP://BLOG.CSDN.NET/ZHANGJG_BLOG/ARTICLE/DETAILS/18369
First, UML diagramSecond, the conceptPrototype mode (PROTOTYPE): Use the prototype example to specify the kind of objects that are created and create new objects by copying the prototypes.Third, the description(1) The prototype pattern is essentially creating another customizable object from one object without needing
1. Prototype pattern definition
The prototype pattern is very simple and is defined as follows:
Specify the kind of objects created with the prototype instance and create new objects by copying the prototypes
2. General class Diagram
The core of the
The prototype pattern is actually creating another customizable object from one object without needing to know the details of any creation.. NET provides the ICloneable interface in the System namespace, which is the only method clone (), so that you can only implement this interface to complete the prototype mode. (choose "Big talk
1. Overview
Create a new instance by copying an existing instance. The copied instance is called a prototype, which is customizable.
2. Role in the pattern
2.1 Abstract Prototype Class (abstract Prototype): Provides a clone interface
2.2 Specific prototype class (concret
1. Features: Consider when the initialization information is not changed.2. Concept: Create a new instance by copying an existing instance. The copied instance is called a prototype, and the prototype is customizable.3. Class Diagram:4. Program implementation: Design Pattern Learning Notes-
Prototype Mode C + + implementation 1 definitionSpecify the kind of objects created with the prototype instance and create new objects by copying the prototypes2 class Diagram3 implementationClass Prototype{ProtectedPrototype ();PublicVirtual prototype* Clone () const = 0;Vitual ~p
Intention
Use the prototype instance to specify the type of object to create and create new objects by copying them.
Scene
There are many similar enemies in the game scene, their skills are the same, but as the enemy appears in different positions, these people's ability is not the same. Let's say we now need to make a team of three infantry, including an elite infantry, with a particularly high capacity. Well, you might be able to create an enemy
Role:
Use the prototype instance to specify the type of object to create and create new objects by copying them.
UML Structure diagram:
Abstract base class:
1 Prototype: Virtual base class, base class for all prototypes, providing clone interface functions
Interface functions:
1 prototype::clone function: A pure virtual function that instantiates the creati
) { - e.printstacktrace (); the } - return NULL;Wuyi } the}4. Examples of application scenarios
An object is used by multiple objects and needs to be modified
Type requires multiple objects but the initialization of the object consumes huge
Pattern implementation in 5.JAVA source code In the JDK source code, all the classes that implement the Cloneable interface use this patt
Prototype mode definition:Use a prototype instance to specify the object type and copy the prototype to create a new object.
The prototype mode allows an object to create another custom object without any details. The working principle is: pass a prototype object to the obje
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.