File tree Expand file tree Collapse file tree 3 files changed +76
-5
lines changed
StructurePattern/BridgePattern Expand file tree Collapse file tree 3 files changed +76
-5
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,20 @@ public class Program
66 {
77 public static void Main ( string [ ] args )
88 {
9+ #region Prototype
10+
11+ Abstraction ab = new RefinedAbstraction ( ) ;
12+
13+ ab . SetImplementor ( new ConcreteImplementorA ( ) ) ;
14+ ab . Operation ( ) ;
15+
16+ ab . SetImplementor ( new ConcreteImplementorB ( ) ) ;
17+ ab . Operation ( ) ;
18+
19+ Console . WriteLine ( ) ;
20+
21+ #endregion Prototype
22+
923 HandsetBrand handsetBrand = new HandsetBrandM ( ) ;
1024 handsetBrand . SetHandsetSoft ( new HandsetMp3 ( ) ) ;
1125 handsetBrand . Run ( ) ;
Original file line number Diff line number Diff line change @@ -11,15 +11,15 @@ internal class ConcreteImplementorA : Implementor
1111 {
1212 public override void Operation ( )
1313 {
14- Console . WriteLine ( "ImplementorA Opearation " ) ;
14+ Console . WriteLine ( "ImplementorA Operation " ) ;
1515 }
1616 }
1717
1818 internal class ConcreteImplementorB : Implementor
1919 {
2020 public override void Operation ( )
2121 {
22- Console . WriteLine ( "ImplementorB Opearation " ) ;
22+ Console . WriteLine ( "ImplementorB Operation " ) ;
2323 }
2424 }
2525
@@ -35,12 +35,12 @@ public void SetImplementor(Implementor implementor)
3535 public abstract void Operation ( ) ;
3636 }
3737
38- internal class RefindAbstraction : Abstraction
38+ internal class RefinedAbstraction : Abstraction
3939 {
4040 public override void Operation ( )
4141 {
4242 Implementor . Operation ( ) ;
43- Console . WriteLine ( "Invoke in RefindAbstraction " ) ;
43+ Console . WriteLine ( "Invoke in RefinedAbstraction " ) ;
4444 }
4545 }
4646}
Original file line number Diff line number Diff line change 22
33## Intro
44
5- 桥接模式
5+ > 桥接模式,将抽象部分与它的实现部分分离,使得它们都可以独立地变化。
6+ >
7+ > 这里说到抽象与它的实现分离指的是抽象类和它的派生类用来实现自己的对象
8+
9+ ## Sample
10+
11+ ``` csharp
12+ internal abstract class Implementor
13+ {
14+ public abstract void Operation ();
15+ }
16+
17+ internal class ConcreteImplementorA : Implementor
18+ {
19+ public override void Operation ()
20+ {
21+ Console .WriteLine (" ImplementorA Operation" );
22+ }
23+ }
24+
25+ internal class ConcreteImplementorB : Implementor
26+ {
27+ public override void Operation ()
28+ {
29+ Console .WriteLine (" ImplementorB Operation" );
30+ }
31+ }
32+
33+ internal abstract class Abstraction
34+ {
35+ protected Implementor Implementor ;
36+
37+ public void SetImplementor (Implementor implementor )
38+ {
39+ Implementor = implementor ;
40+ }
41+
42+ public abstract void Operation ();
43+ }
44+
45+ internal class RefinedAbstraction : Abstraction
46+ {
47+ public override void Operation ()
48+ {
49+ Implementor .Operation ();
50+ Console .WriteLine (" Invoke in RefinedAbstraction" );
51+ }
52+ }
53+
54+
55+ Abstraction ab = new RefinedAbstraction ();
56+
57+ ab .SetImplementor (new ConcreteImplementorA ());
58+ ab .Operation ();
59+
60+ ab .SetImplementor (new ConcreteImplementorB ());
61+ ab .Operation ();
62+ ```
663
764## More
865
You can’t perform that action at this time.
0 commit comments