Skip to content

Commit

Permalink
feat:上传桥接模式例子
Browse files Browse the repository at this point in the history
  • Loading branch information
maxy26 committed Mar 6, 2019
1 parent 63f7cae commit 40c6d97
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* 静态工厂 已上传
* 抽象工厂 已上传

8.桥接模式- 整理中
8.桥接模式- 已上传

9.中介者模式 - 整理中

Expand Down
8 changes: 8 additions & 0 deletions src/main/com/mxy/design/bridge/ALi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.mxy.design.bridge;

public class ALi extends DriverManager {
@Override
protected void useDB(String dbName) {
System.out.println("阿里使用=="+dbName+"==数据库");
}
}
11 changes: 11 additions & 0 deletions src/main/com/mxy/design/bridge/DriverManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.mxy.design.bridge;

/**
* 重点:Bridge 作为核心连接通道
*/
public abstract class DriverManager {

public JDBC jdbc;

protected abstract void useDB(String dbName);
}
9 changes: 9 additions & 0 deletions src/main/com/mxy/design/bridge/JD.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.mxy.design.bridge;


public class JD extends DriverManager {
@Override
protected void useDB(String dbName) {
System.out.println("京东使用=="+dbName+"==数据库");
}
}
10 changes: 10 additions & 0 deletions src/main/com/mxy/design/bridge/JDBC.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.mxy.design.bridge;


public interface JDBC {


String DbName();


}
9 changes: 9 additions & 0 deletions src/main/com/mxy/design/bridge/Mysql.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.mxy.design.bridge;

public class Mysql implements JDBC {

@Override
public String DbName(){
return "MYSQL";
}
}
8 changes: 8 additions & 0 deletions src/main/com/mxy/design/bridge/Oracle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.mxy.design.bridge;

public class Oracle implements JDBC {
@Override
public String DbName(){
return "ORACLE";
}
}
30 changes: 30 additions & 0 deletions src/test/com/mxy/design/bridge/BridgeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.mxy.design.bridge;

import org.junit.Test;

/**
* 桥接模式:是用于把抽象化与实现化解耦,使得二者可以独立变化。这种类型的设计模式属于结构型模式,它通过提供抽象化和实现化之间的桥接结构,来实现二者的解耦。
*/

public class BridgeTest {

@Test
public void logicTest() {

//桥的一端->来者
DriverManager driverManager = new ALi();
//桥的另一端->目的地
driverManager.jdbc = new Mysql();
//建立连接
driverManager.useDB(driverManager.jdbc.DbName());

//桥的另一端->目的地
driverManager = new JD();
driverManager.jdbc = new Oracle();
//建立连接
driverManager.useDB(driverManager.jdbc.DbName());

}


}

0 comments on commit 40c6d97

Please sign in to comment.