定义与结构 定义:用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象。 原型模式的结构: 1) 客户角色:让一个原型克隆自己来得到一个新对象。 2) 抽象原型角色:实现了自己的 clone 方法,扮演这种角色的类通常是抽象类,且它具有 许多具体的子类。 3) 具体原型角色:被复制的对象,为抽象原型角色的具体子类。 源代码: class PrototypeManager { private static PrototypeManager pm; private Map prototypes= null ; private PrototypeManager () { prototypes= new HashMap(); } //使用单例模式来得到原型管理器的唯一实例 public static PrototypeManager getManager () { if (pm== null ) { pm= new PrototypeManager(); } return pm; } public void register (String name , Object prototype) { prototypes.put(name , prototype); } public void unregister (String name) { prototypes.remove