Definition: Specifies the type of object to create with a prototype instance, and creates a new object by copying the prototypes. The prototype mode allows one object to create another customizable object without having to know any details of how it was created, working by passing a prototype object to the object to be created, and creating the object by requesting the prototype object to copy themselves. Applicability: When the class to be instantiated is specified at run time, for example, by dynamic loading, or to avoid creating a factory class hierarchy that is parallel to the product class hierarchy, or when an instance of a class can have only one of several different state combinations. Creating a corresponding number of prototypes and cloning them may be more convenient than manually instantiating the class each time with the appropriate state. Code can explain everything: code part/************************* * Define interface *************************/package Meconsea;
/** * * <p>title:design in Java </p> * * <p>description: Create a batch of clone products </p> * with prototype <p> For information about cloning please refer to another blog</p> * * <p>copyright:copyright (c) 2005</p> * * <p>company:www .hhzskj.com</p> * * @author Meconsea * @version 1.0 * *
Import java.io.Serializable;
Public interface Iprototyperam extends Cloneable, serializable{
/** * for Bean * @return string/public string getName ();
/** * for Bean * @param name String * *
public void SetName (String name);
}
The realization of/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX interface xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/package Meconsea;
/** * * <p>title:design in Java </p> * * <p>description: Create a batch of clone products </p> * with prototype <p> For information about cloning please refer to another blog</p> * * <p>copyright:copyright (c) 2005</p> * * <p>company:www .hhzskj.com</p> * * @author Meconsea * @version 1.0 * *
public class Prototyperam implements iprototyperam{
private String name;
Public String GetName () {return this.name; public void SetName (String name) {this.name = name; }
Public Prototyperam () {this.name = ' this is propotype! '; }
/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX prototype Manager part xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/package Meconsea;
/** * * <p>title: Prototype Manager </p> * * <p>description: Implements the function of automatic registration prototype </p> * <p> prototype manager shipping A row is an instance, so you can use the singleton mode to implement .</p> * <p> references to singleton other blog.</p> * <p>copyright:co Pyright (c) 2005</p> * * <p>company:www.hhzskj.com </p> * * @author Meconsea * @version 1.0 */import A.util.hashmap;
public class Prototypemanager {
/** * Reference to the difference between HashMap and hashtable other blogs * * Private HashMap HM = NULL;
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.