原型模式(Prototype)
概述:
适合场景:
模式架构简单代码实现示例:
<?php
interface Prototype {
public function copy();
}
class ConcretePrototype implements Prototype {
private $_name;
public function __construct($name) { $this->_name = $name; }
public function copy() { return clone $this;}
}
class Demo {}
// client
$demo = new Demo();
$object1 = new ConcretePrototype($demo);
$object2 = $object1->copy();简单场景示例:
Last updated