Home >Backend Development >PHP Tutorial >Detailed explanation of bridge mode of PHP design pattern

Detailed explanation of bridge mode of PHP design pattern

韦小宝
韦小宝Original
2017-11-15 09:38:161719browse

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

Detailed explanation of bridge mode of PHP design pattern

<?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();

Bridge Mode It is one of the core modes for designing Java virtual machines and implementing drivers such as JDBC, and is widely used. In software development, if a class or a system has multiple dimensions of change, you can try to use the bridge mode to design it. The bridge mode provides a complete solution for multi-dimensional changing systems and reduces the complexity of the system

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 pattern

The 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn