File tree Expand file tree Collapse file tree
java-des/src/com/java/design/bridge Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .java .design .bridge ;
2+
3+ public class BlackShoe extends Clothing {
4+
5+ @ Override
6+ public void personDressCloth (Person person ) {
7+
8+ System .out .println (person .getType () + "cloth black shoe ..." );
9+ }
10+ }
Original file line number Diff line number Diff line change 1+ package com .java .design .bridge ;
2+
3+ /**
4+ * 桥接模式 -----> 将抽象部分与它实现部分分离,使他们都可以独立变化
5+ *
6+ * @author Administrator
7+ *
8+ */
9+ public class BridgePattern {
10+
11+ public static void main (String [] args ) {
12+
13+ Man man = new Man ();
14+
15+ Lady lady = new Lady ();
16+
17+ Clothing blackShoe = new BlackShoe ();
18+
19+ Clothing whiteShoe = new WhiteShoe ();
20+
21+ blackShoe .personDressCloth (man );
22+ blackShoe .personDressCloth (lady );
23+
24+ whiteShoe .personDressCloth (man );
25+ whiteShoe .personDressCloth (lady );
26+
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ package com .java .design .bridge ;
2+
3+ public abstract class Clothing {
4+
5+ public abstract void personDressCloth (Person person );
6+
7+ }
Original file line number Diff line number Diff line change 1+ package com .java .design .bridge ;
2+
3+ public class Lady extends Person {
4+
5+ public Lady () {
6+ setType ("Lady ..." );
7+ }
8+ }
Original file line number Diff line number Diff line change 1+ package com .java .design .bridge ;
2+
3+ public class Man extends Person {
4+
5+ public Man () {
6+ setType ("Man ..." );
7+ }
8+ }
Original file line number Diff line number Diff line change 1+ package com .java .design .bridge ;
2+
3+ public abstract class Person {
4+
5+ private Clothing clothing ;
6+
7+ private String type ;
8+
9+ public Clothing getClothing () {
10+ return clothing ;
11+ }
12+
13+ public void setClothing (Clothing clothing ) {
14+ this .clothing = clothing ;
15+ }
16+
17+ public String getType () {
18+ return type ;
19+ }
20+
21+ public void setType (String type ) {
22+ this .type = type ;
23+ }
24+
25+ }
Original file line number Diff line number Diff line change 1+ package com .java .design .bridge ;
2+
3+ public class WhiteShoe extends Clothing {
4+
5+ @ Override
6+ public void personDressCloth (Person person ) {
7+
8+ System .out .println (person .getType () + "cloth white shoe ..." );
9+ }
10+ }
You can’t perform that action at this time.
0 commit comments