File tree Expand file tree Collapse file tree
HeadFirstDesignPatterns/src/facade Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1+ ##表象模式
2+ ____
3+ 表象模式:提供了一個統一的介面,用來存取次系統中的一群介面,表象定義了一個較高層次的介面,讓次系統更容易使用。
4+
5+ 譬如說,一個連續技,包含了三百招六十四掌二十句垃圾話,把招式,掌,垃圾話等等包進Combo表象物件中,把連續技的尻法寫在其中,外面只要對這個表象物件下達使用連續技指令而不用實際一招一招接,相對省事,就算要改掉其中內容,改表象物件即可,使用者不須知道內容改了啥可繼續使用連續技。
6+ ____
Original file line number Diff line number Diff line change 7272
7373一些常見的還有像把Map 轉成Json Object也很合適去製作一個Adapter。
7474____
75+ ##表象模式
76+ ____
77+ 表象模式:提供了一個統一的介面,用來存取次系統中的一群介面,表象定義了一個較高層次的介面,讓次系統更容易使用。
7578
76-
79+ 譬如說,一個連續技,包含了三百招六十四掌二十句垃圾話,把招式,掌,垃圾話等等包進Combo表象物件中,把連續技的尻法寫在其中,外面只要對這個表象物件下達使用連續技指令而不用實際一招一招接,相對省事,就算要改掉其中內容,改表象物件即可,使用者不須知道內容改了啥可繼續使用連續技。
80+ ____
You can’t perform that action at this time.
0 commit comments