forked from hazukac/DesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNightState.java
More file actions
25 lines (24 loc) · 770 Bytes
/
NightState.java
File metadata and controls
25 lines (24 loc) · 770 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
public class NightState implements State {
private static NightState instance = new NightState();
private NightState() {}
public static NightState getInstance() {
return NightState.instance;
}
public void doClock(Context context, int hour) {
if (9 <= hour && hour < 17) {
context.changeState(DayState.getInstance());
}
}
public void doUse(Context context) {
context.callSecurityCenter("Use in night (emergency)");
}
public void doAlarm(Context context) {
context.callSecurityCenter("Ringing alarm (nighttime)");
}
public void doPhone(Context context) {
context.recordLog("Phone (nighttime)");
}
public String toString() {
return "NIGHTTIME";
}
}