File tree Expand file tree Collapse file tree 7 files changed +128
-1
lines changed
Expand file tree Collapse file tree 7 files changed +128
-1
lines changed Original file line number Diff line number Diff line change 3434* 单例模式
3535* 命令模式
3636* 状态模式
37-
37+ * 桥接模式
3838
3939
4040
Original file line number Diff line number Diff line change 1+ package structure .bridge ;/**
2+ * Created by MirsFang on 2017/4/5.
3+ */
4+
5+ import structure .bridge .abs .Implementor ;
6+
7+ /***
8+ *作者:MirsFang
9+ *模式:桥接模式
10+ *时间:2017/04/05/下午12:29
11+ *备注 执行类
12+ ***/
13+
14+ public class BridgeMain {
15+
16+
17+ public static void main (String [] args ) {
18+ //实现化角色
19+ Implementor implementor =new ConcreteImplementor ();
20+ //抽象化角色
21+ RefinedAbstraction refinedAbstraction =new RefinedAbstraction (implementor );
22+ //抽象化角色搞事情
23+ refinedAbstraction .doSomethings ();
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ package structure .bridge ;/**
2+ * Created by MirsFang on 2017/4/5.
3+ */
4+
5+ import structure .bridge .abs .Implementor ;
6+
7+ /***
8+ *作者:MirsFang
9+ *模式:桥接模式
10+ *时间:2017/04/05/下午12:24
11+ *备注 具体实现类
12+ ***/
13+
14+ public class ConcreteImplementor implements Implementor {
15+ @ Override
16+ public void doSomethingA () {
17+ System .out .println ("bridge do something A" );
18+ }
19+
20+ @ Override
21+ public void doSomethingB () {
22+ System .out .println ("bridge do something B" );
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ package structure .bridge ;/**
2+ * Created by MirsFang on 2017/4/5.
3+ */
4+
5+ import structure .bridge .abs .Abstraction ;
6+ import structure .bridge .abs .Implementor ;
7+
8+ /***
9+ *作者:MirsFang
10+ *模式: 桥接模式
11+ *时间:2017/04/05/下午12:28
12+ *备注 具体抽象化角色
13+ ***/
14+
15+ public class RefinedAbstraction extends Abstraction {
16+
17+ public RefinedAbstraction (Implementor implementor ) {
18+ super (implementor );
19+ }
20+
21+ @ Override
22+ public void doSomethings () {
23+ super .doSomethings ();
24+ getImplementor ().doSomethingB ();
25+ }
26+ }
Original file line number Diff line number Diff line change 1+ package structure .bridge .abs ;/**
2+ * Created by MirsFang on 2017/4/5.
3+ */
4+
5+ /***
6+ *作者:MirsFang
7+ *模式:桥接模式
8+ *时间:2017/04/05/下午12:25
9+ *备注 抽象化角色
10+ ***/
11+
12+ public abstract class Abstraction {
13+ private Implementor implementor ;
14+
15+ public Abstraction (Implementor implementor ) {
16+ this .implementor = implementor ;
17+ }
18+
19+ public void doSomethings (){
20+ implementor .doSomethingA ();
21+ }
22+
23+ public Implementor getImplementor (){
24+ return implementor ;
25+ }
26+ }
Original file line number Diff line number Diff line change 1+ package structure .bridge .abs ;
2+
3+
4+ /***
5+ *作者:MirsFang
6+ *模式:桥接模式
7+ *时间:2017/03/01/下午12:34
8+ *备注 实现化角色
9+ ***/
10+ public interface Implementor {
11+ public void doSomethingA ();
12+ public void doSomethingB ();
13+ }
Original file line number Diff line number Diff line change 1+ # 桥接模式
2+
3+ 桥接模式又称桥梁模式。
4+
5+ > 将抽象和实现解耦,使得两者可以独立的变化
6+
7+ 类图在XMind文件中已经有了,可以看出他也是一个比较简单的模式,他有四个角色
8+
9+ * Abstraction 抽象化角色;定义出该角色的行为,同事保存一个实现化角色的引用,一般为抽象类
10+ * Implementor 实现化角色 ;接口或者抽象类,定义角色必须的行为和属性
11+ * RefinedAbstraction 修正抽象化角色;引用实现化角色对抽象化角色进行修正
12+ * ConcreteImplementor 具体实现化角色 ;它实现接口或抽象类定义的方法和属性
13+
You can’t perform that action at this time.
0 commit comments