One ,bridge pattern

*
demand

Set the same function for different phones .

*
code implementation

Mobile function abstract class :
public abstract class HandSetSoft { public abstract void run(); }
Mobile brand abstract class :
public abstract class HandSetBrand { private HandSetSoft soft; public void
setSoft(HandSetSoft soft) { this.soft = soft; } public HandSetSoft getSoft() {
return soft; } public abstract void run(); }
Mobile function implementation class :
public class HandSetGame extends HandSetSoft { @Override public void run() {
System.out.println(" Run mobile games "); } } public class HandSetAddressList extends
HandSetSoft { @Override public void run() { System.out.println(" Run phone book "); } }
Mobile brand realization :
// Mobile phone brand N public class HandSetBrandN extends HandSetBrand { @Override public
void run() { super.getSoft().run(); } } // Mobile phone brand S public class HandSetBrandS
extends HandSetBrand { @Override public void run() { super.getSoft().run(); } }
Test class :
public class Test { public static void main(String[] args) { // mobile phone N brand
HandSetBrand abN = new HandSetBrandN(); abN.setSoft(new HandSetGame());
abN.run(); abN.setSoft(new HandSetAddressList()); abN.run(); // mobile phone S brand
HandSetBrand abS = new HandSetBrandS(); abS.setSoft(new HandSetGame());
abS.run(); abS.setSoft(new HandSetAddressList()); abS.run(); } }
Two , Bridge mode definition

         Separate the abstract part from its implementation part , So that they can change independently . For the above example , In fact, mobile phones can be classified by brand , It can also be classified by function . If you add new features or new brands of mobile phones , All you need to do is add an implementation class .

Bridge mode structure diagram :

 

 

 

Technology
©2019-2020 Toolsou All rights reserved,
html Writing about cherry trees , Writing about cherry trees It's unexpected Python Cherry tree (turtle The gorgeous style of Library ) Browser kernel ( understand )HashMap Explain in detail java Four functional interfaces ( a key , simple )os Simple use of module Some East 14 Pay change 16 salary , Sincerity or routine ?