Prototype Mode prototype
Prototype mode is also a mode of creation, as the name implies, is to create a new object identical to the original. For example, the daily development, commonly used in the replication function, the user creates a new financial voucher, the future will have similar credentials, but the amount needs to be modified, the other content is the same. At this point, the user does not need to re-enter the contents of the credential one by one into the interface, just to perform the copy function, you can generate a new identical voucher, and then the new voucher only modify the amount, then use the prototype mode.
Description: Java An object assignment is an address pass, and modifying an assigned instance modifies the property value of the original instance, and we need to modify the property value of the original instance without modifying it after copying it.
Prototype mode
method: Implement the Cloneable class in Java
Implements Cloneable
Public Object Clone () {Object obj = Null;try{obj = Super.clone ();} catch (Clonenotsupportexception ex) {System.out.println (ex);} return OJB;}
Client calls:
Product p = new product ();p. Setnum (111);p. Setprice (+);p. Setrebate (20); Product P1 = (product) p.clone ();p 1.setNum (200);
What we get is that the number of modified P1 and P is different.
Design mode (quad) prototype mode (PROTOTYPE)-Create type