-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
maxy26
committed
Mar 6, 2019
1 parent
63f7cae
commit 40c6d97
Showing
8 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
* 静态工厂 已上传 | ||
* 抽象工厂 已上传 | ||
|
||
8.桥接模式- 整理中 | ||
8.桥接模式- 已上传 | ||
|
||
9.中介者模式 - 整理中 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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+"==数据库"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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+"==数据库"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.mxy.design.bridge; | ||
|
||
|
||
public interface JDBC { | ||
|
||
|
||
String DbName(); | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
|
||
} | ||
|
||
|
||
} |