Bridging mode in Java

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.