background
Sometimes you will find that the reference type is also very annoying, because at some point you may need two of the same reference object, one for backup, one to continue operation, but continue operation that does not affect my backup that, this time the trouble comes, two references if point to the same memory space object, Then modify one, and the other will certainly change.
1. Intention to use
Instead of re-initializing the object, you dynamically get the state of the object runtime.
2. Life Example
The process of setting up a copy is a prototype model, where you can make targeted changes to a specific area, and then copy it again with the modified data!
3. Java Example (framework, JDK, JEE)
Not clear where if anyone knows can add
4. Pattern class Diagram
5. Advantages of the Model
Prototype mode: Specifies the kind of object created with the prototype instance, and creates a new object by copying the prototypes.
The prototype pattern is actually one more customizable object from one object and no need to know the details of any creation.
Cloning is generally the best way to initialize information without changing it, cloning both hides the details of the object creation, and there is a significant improvement in performance.
Instead of re-initializing the object, you dynamically get the state of the object runtime.
Prototype mode using cloning will certainly involve deep replication and shallow copy, Java implementation of the direct substitution clone method, but that is shallow copy, the true use of deep replication also need to implement the serializable interface, or the object type of data deep depth clone.
6. Comparison with similar models
The feeling prototype pattern is used very little, because he is a backup of the object data, when we define a class, we often give some of his member variables to initialize, do not know if such a new object is not the same as the prototype model is the same reason? Oh..........
The design pattern of the vegetable--prototype mode