forked from echoTheLiar/JavaCodeAcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathState.java
More file actions
44 lines (31 loc) · 738 Bytes
/
State.java
File metadata and controls
44 lines (31 loc) · 738 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
35
36
37
38
39
40
41
42
43
44
package designpattern.state;
/**
* 抽象状态类
*
* @author liu yuning
*
*/
public abstract class State {
public abstract void handle(Context context);
}
class ConcreteStateA extends State {
@Override
public void handle(Context context) {
System.out.println("现在是在状态A");
context.setState(new ConcreteStateB());
}
}
class ConcreteStateB extends State {
@Override
public void handle(Context context) {
System.out.println("现在是在状态B");
context.setState(new ConcreteStateC());
}
}
class ConcreteStateC extends State {
@Override
public void handle(Context context) {
System.out.println("现在是在状态C");
context.setState(new ConcreteStateA());
}
}