Java uses bridge mode to realize the functions of switch and electric lamp lighting

This article illustrates how Java uses bridge mode to realize the functions of switch and electric lamp lighting. Share with you for your reference, as follows:

Model definition

Bridge mode, also known as bridge mode, has two or more dimensional changes in the software system due to its own logic. How to deal with this multi-dimensional change, bridge mode enables the software system to change easily in multiple directions without introducing additional complexity.

The three key words of bridge mode are: abstraction, realization and decoupling

Two. Example of model

1 bridge mode analysis method

We use electric lighting to illustrate this mode. Instead of inheritance, the strong association between switch and lamp is changed into weak association by object combination.

2 bridge mode static class model

3 code example

3.1 create light interface

3.2 creating general switches

3.3 creating a remote control switch

3.4 realization of incandescent lamp

3.5 realization of crystal lamp

3.6 general switch controls incandescent lamp, and remote control switch controls crystal lamp

Operation results:

3.7 the general switch controls the crystal lamp, and the remote control switch controls the incandescent lamp

Operation results

3、 Design principles

1. Try to use object aggregation weak association and avoid using inheritance strong association. 2 abstraction and realization decoupling.

4、 Use occasion

1. Do not want to have a fixed binding relationship between the abstract class and the implementation part. 2. The abstract and implementation parts of the class should be expanded by the method of single class. 3. The modification of an abstract implementation part will not affect the customer, that is, the customer code does not need to be recompiled

5、 Bridge mode static class diagram

For more information about Java algorithms, readers who are interested can see the topics on this site: Java data structure and algorithm tutorial, summary of Java DOM node operation skills, summary of java file and directory operation skills, and summary of Java cache operation skills

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>