Skip to content

Commit 1414818

Browse files
committed
merge ;
2 parents 9407432 + 8b0fbe6 commit 1414818

22 files changed

Lines changed: 323 additions & 8 deletions

HeadFirstDesignPatterns/src/decorate/Weapon.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22

33
public interface Weapon {
44
public int makeDamage();
5-
65
public String getHurtVerb();
76
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package factory;
2+
3+
import factory.company.ABCompany;
4+
import factory.company.MMCompany;
5+
import factory.company.SWCompnay;
6+
7+
public class Go {
8+
9+
public static void main(String[] args) {
10+
SWCompnay mSwCompnay = new MMCompany();
11+
mSwCompnay.releaseSoftwareProject("SOAP");
12+
SWCompnay mSwCompnay2 = new ABCompany();
13+
mSwCompnay2.releaseSoftwareProject("RESTFUL");
14+
}
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## 工廠模式
2+
____
3+
定義了一個建立物件的介面,但由次類別決定要實體化的類別為何者。工廠方法讓類別把實體化的動作,交由次類別進行。
4+
5+
(盡量)
6+
7+
* 變數不可以持有具象類別的參考。
8+
* 不要讓類別繼承自具象類別
9+
* 不要讓次類別中的方法推翻超類別的方法
10+
_____
11+
12+
13+
##抽象工廠模式
14+
____
15+
定義了一個介面,建立相關或相依物件之家族,而不需要明確指定具象類別。
16+
17+
對於單一個物件創造使用的是工廠模式,對於一堆物件組合成的物件,可用抽象工廠去創造一堆物件的介面,然後由工廠決定實作的具象類別。
18+
____
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package factory.client;
2+
3+
public interface ClientCode {
4+
public void Go();
5+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package factory.client;
2+
3+
import util.JavaLog;
4+
5+
public class EngineerDeyu implements ClientCode{
6+
7+
@Override
8+
public void Go() {
9+
JavaLog.d("Crush");
10+
}
11+
12+
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package factory.client;
2+
3+
import util.JavaLog;
4+
5+
public class EngineerJay implements ClientCode{
6+
7+
@Override
8+
public void Go() {
9+
JavaLog.d("Is dirty? oh Dirty");
10+
}
11+
12+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package factory.cloud;
2+
3+
public interface CloudCode {
4+
public void Go();
5+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package factory.cloud;
2+
3+
import util.JavaLog;
4+
5+
public class EngineerLeo implements CloudCode{
6+
@Override
7+
public void Go() {
8+
JavaLog.d("This use React and Lavaral framwork");
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package factory.cloud;
2+
3+
import util.JavaLog;
4+
5+
public class EngineerTim implements CloudCode{
6+
@Override
7+
public void Go() {
8+
JavaLog.d("Nnnnnn~~~~~");
9+
}
10+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package factory.company;
2+
3+
import factory.pm.PM;
4+
import factory.pm.PMKen;
5+
import factory.project.ProjectRestful;
6+
import factory.project.ProjectSoap;
7+
import factory.project.SoftwareProject;
8+
9+
public class ABCompany extends SWCompnay{
10+
11+
private PM mPM = new PMKen();
12+
@Override
13+
protected SoftwareProject createSoftwareProject(String type) {
14+
SoftwareProject mSoftwareProject = null;
15+
if(type.equals("SOAP")){
16+
mSoftwareProject = new ProjectSoap(mPM);
17+
}
18+
if(type.equals("RESTFUL")){
19+
mSoftwareProject = new ProjectRestful(mPM);
20+
}
21+
return mSoftwareProject;
22+
}
23+
24+
}

0 commit comments

Comments
 (0)