"; mscore = pscore;} deep copy: Public personcloneobject (score pscore) {mname = "James"; Mmajor = "it"; mscore = (score) pscore. clone ();}
Code: https://github.com/bird7310/DesignPatternExample.git
Package name: COM. ahacool. designpattern. Prototype
3. Conclusion
It's not easy to write a blog. I admire those who have written many blogs and published books. It is really difficult to write things clearly and write so many articles.
At present, the i
The intent of the prototype pattern is to specify the type of object to create with the prototype instance, and to create a new object by copying the prototypes.
Applicabilitywhen the class being instantiated is specified at run time, for example, by dynamic loading;To avoid creating a factory class level that is parallel to the product class hierarchy;When an i
The following is what I learned today. I read the book "big talk Design Pattern". Many of the Code is the code in the book, but it is my own understanding. Remember it as a learning note.
Today we are learning the prototype:
The class diagram is as follows:--- The image is not uploaded --!
For example, to design a res
ObServer1 ()), $event->addobserver (New ObServer2 ()), $event Tringger ();prototype ModeSimilar to Factory mode, used to create objects, the prototype schema creates a good one prototype object, creates a new object through the Clone prototype object, avoids repetitive initialization when the class is created, and is
Prototype pattern is a creation mode. In the gof book, its intention is described as specifying the object type with the prototype instance, and creating new objects by copying these prototypes.
Prototype pattern itself is actually very simple. Any object that provides the
applications, it is often not desirable to have such a thing, that is, the copy object can not be changed to affect the original object. The reason is simple, not because Tom chose C # This course requires Jim must also change the selected C + + course to C #. To solve this problem, you need to copy a completely new object, deep copy.Let's change the student class and the course Class a little bit, and create a new student by serializing and deserializing:[Serializable] Public classCourse { Pub
During the interview, the interviewer always asked questions about the design model. Although we will inadvertently use the design model when writing the program, we still cannot tell in front of the interview manager, here I have recorded some of the design patterns that I have seen to help me better use them.
[Prototype
Design Pattern series prototype PatternPrototype mode specifies the type to be created through the instance object, which is essentially different from the factory method mode we mentioned in the previous article, the factory method mode defines different subclasses through inheritance of classes to create different types of objects. It belongs to the class mode.
I. Motivation and definition
Previous Prototype Learning has always assumed that the prototype is intended to easily create identical or similar objects, replace the new method by copying objects, and also studies deep cloning and shortest cloning. Recently I carefully read the gof design model and found that the prototype
= new A (); now you want to generate an instance B like car1, according to the prototype mode, it should be like this: A B =. clone (); instead of creating a new a object. Through the above sentence, we can get an instance that is the same as a. Specifically, it should be that their data members are the same. The prototype mode returns an object A without using the new operation.
2. What are the benefits o
This series mainly records what the design pattern intends to be, what issues it wants to solve, and when it can be used; how it solves it, master its structure diagram, remember its key code; be able to think of at least two of its application instances, one in life and one in software; What are the advantages and disadvantages of this model, and what use scenarios are there, what should I pay attention to
, some common sense friends know that the iombies are chicken cakes with cream. They are all cloned one by one with abrasive tools, so they look like the same in general. Mayonnaise has many flavors including strawberry with cream, fresh orange, and so on. So are there many egg factories that want to produce all kinds of egg tools. The answer is no! It is impractical to change the production pipeline for every kind of egg yolk pie in the factory. In fact, it is very easy to add the containers in
the builder object it wants. Director obtains the customer's request to create the product, finally obtains the product.
Advantages1. The process of constructing objects can be finely controlled to produce different product objects.2. Easy to expand, there are new products, just add new concretebuilder can be achieved.
Related modeThe abstract factory pattern is similar to a generator because it can also create complex objects. The main difference
Use a prototype instance to specify the type of the object to be created and copy the original object to create a new object.
Public class prototypeclass implements cloneable {@ override protected object clone () {// todo auto-generated method stub prototypeclass = NULL; try {prototypeclass = (prototypeclass) super. clone ();} catch (clonenotsupportedexception e) {// todo auto-generated Catch Block E. printstacktrace ();} return prototypeclass ;}}
Design Pattern _ prototype PatternPrototype Pattternspecify the kinds of objects to create using a prototypical instance, and create new objects by coping this prototype. (use a prototype instance to specify the type of the object to be created and copy the
Prototype: Use a prototype instance to specify the object type and copy the prototype to create a new object.
Prototype, Prototype class, declares an interface for cloning itself
ConcretePrototype1 and ConcretePrototype2 are specific
In prototype mode, a prototype instance is used to specify the type of the object to be created, and a new object is created by copying the prototype.
The Prototype mode is a creation design mode. The Prototype mode allows an obje
The prototype mode is an object creation mode.Use a prototype instance to specify the type of the object to be created and copy the prototype to create a new object.The prototype mode allows an object to create another custom object without any details.The basic working principle of the
Label: style blog HTTP color Io OS SP Div 2014
1. My description
In my understanding, what is the prototype mode is to clone n objects. The cloned object should be exactly the same. Of course, you can modify the content of the cloned object. For C ++, the copy constructor is used. This mode is relatively simple, so it is no longer arrogant.
Ii. UML diagram
3. My code
#include
Design
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.