Skip to content

Commit ee48b6f

Browse files
deyudeyu
authored andcommitted
add facade pattern
1 parent a37a8e8 commit ee48b6f

4 files changed

Lines changed: 55 additions & 1 deletion

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package facade;
2+
3+
import adapter.Item;
4+
import decorate.Weapon;
5+
6+
public class ComboFacade {
7+
Weapon mWeapon1;
8+
Weapon mWeapon2;
9+
Item mItem;
10+
11+
public ComboFacade(Weapon weapon, Weapon weapon2 , Item item ) {
12+
this.mWeapon1 = weapon;
13+
this.mWeapon2 = weapon2;
14+
this.mItem = item;
15+
}
16+
17+
public String TwoWeaponCombo(){
18+
return mWeapon1.getHurtVerb() + mWeapon2.getHurtVerb();
19+
}
20+
21+
public String AttackAndUseItemCombo(){
22+
return mWeapon1.getHurtVerb() + mItem.useWord();
23+
}
24+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package facade;
2+
3+
import util.JavaLog;
4+
import adapter.Banana;
5+
import adapter.Item;
6+
import decorate.Arrow;
7+
import decorate.Sword;
8+
import decorate.Weapon;
9+
10+
public class Go {
11+
12+
public static void main(String[] args) {
13+
Weapon w1 = new Arrow();
14+
Weapon w2 = new Sword();
15+
Item i1 = new Banana();
16+
ComboFacade mCF = new ComboFacade(w1, w2, i1);
17+
JavaLog.d(mCF.AttackAndUseItemCombo());
18+
JavaLog.d(mCF.TwoWeaponCombo());
19+
}
20+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
##表象模式
2+
____
3+
表象模式:提供了一個統一的介面,用來存取次系統中的一群介面,表象定義了一個較高層次的介面,讓次系統更容易使用。
4+
5+
譬如說,一個連續技,包含了三百招六十四掌二十句垃圾話,把招式,掌,垃圾話等等包進Combo表象物件中,把連續技的尻法寫在其中,外面只要對這個表象物件下達使用連續技指令而不用實際一招一招接,相對省事,就算要改掉其中內容,改表象物件即可,使用者不須知道內容改了啥可繼續使用連續技。
6+
____

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,9 @@ ____
7272

7373
一些常見的還有像把Map 轉成Json Object也很合適去製作一個Adapter。
7474
____
75+
##表象模式
76+
____
77+
表象模式:提供了一個統一的介面,用來存取次系統中的一群介面,表象定義了一個較高層次的介面,讓次系統更容易使用。
7578

76-
79+
譬如說,一個連續技,包含了三百招六十四掌二十句垃圾話,把招式,掌,垃圾話等等包進Combo表象物件中,把連續技的尻法寫在其中,外面只要對這個表象物件下達使用連續技指令而不用實際一招一招接,相對省事,就算要改掉其中內容,改表象物件即可,使用者不須知道內容改了啥可繼續使用連續技。
80+
____

0 commit comments

Comments
 (0)