There are some more confusing patterns in design mode, such as adapter mode and bridging mode, all of which allow two classes to work in one piece
However, although they are very similar, are indirect reference objects, there will be different, let's look at the following analysis
One, each said its long
The adapter mode says, "I'm the interface that transforms a class's interface into another class so they can work together. ”
Bridging mode says, "What is there that I can separate the abstraction from the realization, and let them do it separately?"
Adapter mode refused, then said: "Yao in the NBA playing basketball, the coach to arrange tactics, but he can not understand, need to translate, then turn
The role of the adapter, I can put Yao and coach fit to a piece, so that Yao can understand the tactics, you can? ”
Bridging mode A contemptuous smile: "Although I can not start the adaptation role, but I can abstract mobile phone function and mobile phone brand, so that the same work
Can be used in different brands, the same brand can use different functions, you can resemble if there is no bridging mode, then a function can only be
It's a special phone, isn't it sad? "
Second, Comparison
From the top of the adapter and bridge mode is to let two classes work in one piece, then what is the difference between them?
Adapter mode: Change the interface to allow two classes to be compatible
Bridging mode: Separate abstraction and implementation, interface different, purpose is to separate
So to speak: if there are now two modules, you want them to work in a piece, then use adapter mode;
is to separate the implementation, then the bridge mode, bridge mode implementation, both sides of the things can be free change, but the interface is stable
Two modes of application with different design stages
Bridge mode is applied in the early stage of the design, and the force is more flexible in the system. Adapter mode applications Some classes do not work together after the design is complete.
Then use the adapter mode
In general, adapter mode and bridge mode will appear in pairs
Iii. Summary
Learn to learn from the old knowledge, and learn to compare learning, then learn more efficient
Design mode of learning is not finished, after the accumulation of 1.1 points
Analysis of adapter and bridge mode