PHP设计模式之:装饰模式
<?php
// 人类
class Person
{
private
$name;
public function __construct($name)
{
$this->name =
$name;
}
public function
Show()
{
echo
"装扮" . $this->name;
}
}
//服饰类
class Finery
extends Person
{
protected
component;
public function Decoration(Person
$component)
{
$this->component = $component;
}
public function Show()
{
if($this->component !=
null)
{
$this->component->Show();
}
}
}
// 具体服饰类
class TShirts extends
Finery
{
public function Show()
{
echo "T 恤";
$this->Show();
}
}
class BigTrouser extends Finery
{
public function Show()
{
echo "大裤";
$this->Show();
}
}
class Suit extends
Finery
{
public function Show()
{
echo "西装";
$this->Show();
}
}
$p = new Person("狗娘养的");
$bt = new
BigTrouser();
$bt.Decoration($p);
$bt.Show();
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。