Bridging mode in English is bridge, bridging mode is concerned with abstract design. An abstraction is a class that contains a set of abstract methods that may contain multiple implementations.
The general practice of implementing abstractions is to create a hierarchy of classes, at the top of which is an abstract class that contains abstract methods, each of which provides different implementations of these abstract methods. However, this approach is not sufficient when subclasses of this hierarchy are required.
You can create a bridge and then move these abstract methods into an interface so that the abstraction relies on the implementation of the interface.
The purpose of bridging mode is to decouple the implementation of abstract and abstract methods so that the two can be independent of each other.
The meaning of this passage is to separate the realization from the abstract.
Here is an example to illustrate:
1. There are apples and oranges in the fruit now.
2. People are divided into men and women
3. People can eat fruit, so there are 2*2 = 4 of the situation
If we do not use bridging mode, then the implementation of so many situations need one to achieve, that is, 4 classes, then we used bridging mode? The answer is: Class 2. This advantage will be more obvious in the case of more conditions and implementations.
Specific implementation:
The UML diagram of the implementation is given below first