新聞中心
今天小編給大家分享一下php橋接模式實(shí)例分析的相關(guān)知識點(diǎn),內(nèi)容詳細(xì),邏輯清晰,相信大部分人都還太了解這方面的知識,所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。

北安網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),北安網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為北安成百上千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)營銷網(wǎng)站建設(shè)要多少錢,請找那個售后服務(wù)好的北安做網(wǎng)站的公司定做!
說明
1、將兩個原本不相關(guān)的類結(jié)合在一起,然后利用兩個類中的方法和屬性,輸出一份新的結(jié)果。
2、結(jié)構(gòu)分為抽象類、被提煉的抽象類、實(shí)現(xiàn)類、具體實(shí)現(xiàn)類和客戶端代碼。
實(shí)例
/**
* 顏色抽象類
* Class Colour
*/
abstract class Colour
{
/**
* @return mixed
*/
abstract public function run();
}
/**
* 黑色
* Class Black
*/
class Black extends Colour
{
public function run()
{
// TODO: Implement run() method.
return '黑色';
}
}
/**
* 白色
* Class White
*/
class White extends Colour
{
public function run()
{
// TODO: Implement run() method.
return '白色';
}
}
/**
* 紅色
* Class Red
*/
class Red extends Colour
{
public function run()
{
// TODO: Implement run() method.
return '紅色';
}
}
/**
* 形狀抽象類
* Class Shape
*/
abstract class Shape
{
/**
* 顏色
* @var Colour
*/
protected $colour;
/**
* Shape constructor.
* @param Colour $colour
*/
public function __construct(Colour $colour)
{
$this->colour = $colour;
}
/**
* @return mixed
*/
abstract public function operation();
}
/**
* 圓形
* Class Round
*/
class Round extends Shape
{
/**
* @return mixed|void
*/
public function operation()
{
// TODO: Implement operation() method.
echo $this->colour->run() . '圓形
';
}
}
/**
* 長方形
* Class Rectangle
*/
class Rectangle extends Shape
{
/**
* @return mixed|void
*/
public function operation()
{
// TODO: Implement operation() method.
echo $this->colour->run() . '長方形
';
}
}
/**
* 正方形
* Class Square
*/
class Square extends Shape
{
/**
* @return mixed|void
*/
public function operation()
{
// TODO: Implement operation() method.
echo $this->colour->run() . '正方形
';
}
}
// 客戶端代碼
// 白色圓形
$whiteRound = new Round(new White());
$whiteRound->operation();
// 黑色正方形
$blackSquare = new Square(new Black());
$blackSquare->operation();
// 紅色長方形
$redRectangle = new Rectangle(new Red());
$redRectangle->operation();
// 運(yùn)行結(jié)果
白色圓形
黑色正方形
紅色長方形以上就是“php橋接模式實(shí)例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會為大家更新不同的知識,如果還想學(xué)習(xí)更多的知識,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
網(wǎng)站名稱:php橋接模式實(shí)例分析
文章源于:http://www.dlmjj.cn/article/ihjojh.html


咨詢
建站咨詢
