Skip to content

Commit 29046e6

Browse files
authored
桥接模式
桥接模式
1 parent f196dfb commit 29046e6

File tree

7 files changed

+96
-0
lines changed

7 files changed

+96
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.java.design.bridge;
2+
3+
public abstract class Clothing {
4+
5+
public abstract void personDressCloth(Person person);
6+
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.java.design.bridge;
2+
3+
public class Lady extends Person {
4+
5+
public Lady() {
6+
setType("Lady ...");
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.java.design.bridge;
2+
3+
public class Man extends Person {
4+
5+
public Man() {
6+
setType("Man ...");
7+
}
8+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy