桥接模式(Bridging mode)

菜鸟解释:

  桥接(Bridge)是用于把抽象化与实现化解耦,使得二者可以独立变化。这种类型的设计模式属于结构型模式,它通过提供抽象化和实现化之间的桥接结构,来实现二者的解耦。

本人理解:

  主要适用与两种维度的变化,比如我想创造不同尺寸和颜色的轮子,此时颜色和轮子又是单独分开的,这时候需要两个接口 一个是颜色一个是尺寸,这是需要把颜色和尺寸连接起来,这是

创建一个颜色结构,然后创建一个尺寸的抽象了类,在尺寸中创建颜色的引用,在构造方法中需要传入颜色的实例,这时候在尺寸的子类中就有了颜色和尺寸两个东西,这时就可以造出各种尺寸和颜色的轮子了

————————

Rookie explanation:

Bridge is used to decouple abstraction from realization, so that they can change independently. This type of design pattern belongs to structural pattern, which realizes the decoupling of abstraction and realization by providing a bridge structure between abstraction and realization.

I understand:

It is mainly applicable to the changes of two dimensions. For example, I want to create wheels of different sizes and colors. At this time, the color and wheel are separate. At this time, two interfaces are required, one is color and the other is size. This is to connect the color and size. This is

Create a color structure, and then create an abstract class of size. Create a reference to color in the size. You need to pass in an instance of color in the construction method. At this time, there are color and size in the subclass of size. At this time, you can create wheels of various sizes and colors