Bridge mode of design model (including UML complete example)

Design the bridging mode of the design model

1. Bridge Mode

1.1 Definition and characteristics

  Bridge Pattern (Bridge Pattern), the abstract part is separated from its implementation part, so that they can be changed independently. The easier-to-understand expression is: the implementation system can be classified from multiple dimensions, the bridge mode abstracts each dimension, and each dimension changes independently, and then the inheritance relationship can be replaced by the combination relationship, reducing the coupling between each dimension and reducing the subclass number.

1.2 Structure of the model

  Bridge mode includes the following main roles:

  • Abstraction (Abstraction) role: define an abstract class and contain a reference to the realization of the object.
  • Refined
    Abstraction (Refined Abstraction) role: is a subclass of the abstract role, implements the business methods in the parent class, and calls the business methods in the realized role through the combination relationship.
  • Implementor (Implementor) role: Defines the interface of the implementor role, which is used by the extended abstract role call.
  • Concrete Implementor role: Gives the concrete realization of the implement role interface.

1.3 Origin of the problem

  In real life, some categories have two or more dimensions of change, such as graphics can be divided by shape and color. How to design software like Photoshop that can draw graphics with different shapes and different colors? If inheritance is used, there are m × n types of graphics with m shapes and n colors, which not only have many corresponding subclasses, but also difficult to expand.

1.4 Solutions

  It is to use the bridge mode to abstract each dimension, each dimension changes independently, and then the inheritance relationship can be replaced by the combination relationship, which reduces the coupling between each dimension and reduces the number of subclasses.
  UML class diagram, to solve the case, please see the principle of composite reuse of design principles (including a complete example of UML class diagram).
  In fact, the bridge mode is designed using the principle of composite reuse.

1.5 UML types

1.6 Solution

Published 56 original articles · Like1 · Visits1168

Guess you like

Origin blog.csdn.net/atu1111/article/details/105470181