Bridge modeUsing a clever way to deal with the problems of multi-layer inheritance, Bridge modereplaces traditional multi-layer inheritance with abstract association, and separates the static relationships between classes. The inheritance relationship is converted into a dynamic object combination relationship. Bridge mode makes the system more flexible and easy to expand, while effectively controlling the number of classes in the system
##Bridge The concept of:
Separate the abstract part from its implementation part so that they can both change independently<?php /* * 桥接模式 */ interface allPan { public function setColor(); } abstract class Pan { public $color; public function setColor() { } public function write() { } } class maxPan extends Pan { public function write() { $this->color->setcolor(); echo "写出来的粗体字"; } } class smallPan extends Pan { public function write() { $this->color->setcolor(); echo "写出来的细体字"; } } class Red implements allPan { public function setColor() { echo "红色"; } } class Blick implements allPan { public function setColor() { echo "黑色"; } } function testDriver() //客户端 { $colors = new maxPan(); $colors->color = new Red(); $colors->write(); } testDriver();
Related recommendations:
Detailed explanation of strategy pattern of PHP design pattern
Detailed explanation of proxy pattern of PHP design pattern
##PHP design Pattern of simple factory patternThe above is the detailed content of Detailed explanation of bridge mode of PHP design pattern. For more information, please follow other related articles on the PHP Chinese website!