Detailed explanation of bridge mode of PHP design pattern

韦小宝
Release: 2023-03-17 14:18:02
Original
1578 people have browsed it

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();
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!