- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemyShipFactory.java
More file actions
Latest commit
20 lines (18 loc) · 582 Bytes
/
Copy pathEnemyShipFactory.java
File metadata and controls
20 lines (18 loc) · 582 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
packagedesignPattern.Factory;
//This is a factory thats only job is creating ships
//By encapsulating ship creation, we only have one
//place to make modifications
publicclassEnemyShipFactory {
// This could be used as a static method if we
// are willing to give up subclassing it
publicEnemyShipmakeEnemyShip(StringnewShipType) {
if (newShipType.equals("U")) {
returnnewUFOEnemyShip();
} elseif (newShipType.equals("R")) {
returnnewRocketEnemyShip();
} elseif (newShipType.equals("B")) {
returnnewBigUFOEnemyShip();
} else
returnnull;
}
}