<?php
// 原型接口
interface Prototype
{
public function clone();
}
// 具体原型类
class ConcretePrototype implements Prototype
{
private $name;
public function __construct($name)
{
$this->name=$name;
}
public function clone()
{
return new ConcretePrototype($this->name);
}
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name=$name;
}
}
// 客户端代码
$prototype=new ConcretePrototype(“Prototype”);
$clone=$prototype->clone();
echo $clone->getName(); // 输出 “Prototype”
// 原型接口
interface Prototype
{
public function clone();
}
// 具体原型类
class ConcretePrototype implements Prototype
{
private $name;
public function __construct($name)
{
$this->name=$name;
}
public function clone()
{
return new ConcretePrototype($this->name);
}
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name=$name;
}
}
// 客户端代码
$prototype=new ConcretePrototype(“Prototype”);
$clone=$prototype->clone();
echo $clone->getName(); // 输出 “Prototype”
© 版权声明
文章版权归作者所有,未经允许请勿转载。