-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.java
More file actions
31 lines (25 loc) · 801 Bytes
/
Copy pathmain.java
File metadata and controls
31 lines (25 loc) · 801 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
/**
* @author: Ly Tran Vinh
* @contact: [email protected]
* @content: State Pattern
*/
import Concretes.*;
import Interfaces.*;
import Contexts.PhoneContext;
public class main {
public static void main(String[] args) {
// Creating a phone with an initial state of LockedState
PhoneContext phone = new PhoneContext(new LockedState());
// Pressing button when the phone is locked
phone.pressButton();
// Changing state to Unlocked
phone.setState(new UnlockedState());
phone.pressButton();
// Changing state to LowBattery
phone.setState(new LowBatteryState());
phone.pressButton();
// Changing state back to Locked
phone.setState(new LockedState());
phone.pressButton();
}
}