forked from rick2785/JavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemyShipFactory2.java
More file actions
34 lines (19 loc) · 628 Bytes
/
EnemyShipFactory2.java
File metadata and controls
34 lines (19 loc) · 628 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// This is a factory thats only job is creating ships
// By encapsulating ship creation, we only have one
// place to make modifications
public class EnemyShipFactory2{
// This could be used as a static method if we
// are willing to give up subclassing it
public EnemyShip2 makeEnemyShip(String newShipType){
EnemyShip newShip = null;
if (newShipType.equals("U")){
return new UFOEnemyShip3();
} else
if (newShipType.equals("R")){
return new RocketEnemyShip2();
} else
if (newShipType.equals("B")){
return new BigUFOEnemyShip2();
} else return null;
}
}