外观模式
外观模式:为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一子类系统更加容易使用。
class Stock1
{
public function sell(){
echo '卖股票1<br>';
}
public function buy(){
echo '买股票1<br>';
}
}
class Stock2
{
public function buy(){
echo '买股票2<br>';
}
public function sell(){
echo '卖股票2<br>';
}
}
class NationDebt
{
public function buy(){
echo '买国债<br>';
}
public function sell(){
echo '卖国债<br>';
}
}
class Real
{
public function buy(){
echo '购买房地产<br>';
}
public function sell(){
echo '卖地产<br>';
}
}
class Found
{
private $stock1;
private $stock2;
private $nationDebt;
private $real;
public function __construct()
{
$this->stock1 = new Stock1();
$this->stock2 = new Stock2();
$this->nationDebt = new NationDebt();
$this->real = new Real();
}
public function buyFound(){
$this->stock1->buy();
$this->stock2->buy();
$this->nationDebt->buy();
$this->real->buy();
}
public function sellFound(){
$this->stock1->sell();
$this->stock2->sell();
$this->nationDebt->sell();
$this->real->sell();
}
}
$found = new Found();
$found->buyFound();
$found->sellFound();