1700473077
1700473078
public void close();
1700473079
1700473080
//电梯要能上能下,运行起来
1700473081
1700473082
public void run();
1700473083
1700473084
//电梯还要能停下来
1700473085
1700473086
public void stop();
1700473087
1700473088
}
1700473089
1700473090
这里增加了4个静态常量,并增加了一个方法setState,设置电梯的状态。我们再来看实现类是如何实现的,如代码清单26-5所示。
1700473091
1700473092
代码清单26-5 电梯实现类
1700473093
1700473094
public class Lift implements ILift{
1700473095
1700473096
private int state;
1700473097
1700473098
public void setState(int state){
1700473099
1700473100
this.state=state;
1700473101
1700473102
}
1700473103
1700473104
//电梯门关闭
1700473105
1700473106
public void close(){
1700473107
1700473108
//电梯在什么状态下才能关闭
1700473109
1700473110
switch(this.state){
1700473111
1700473112
case OPENING_STATE://可以关门,同时修改电梯状态
1700473113
1700473114
this.closeWithoutLogic();
1700473115
1700473116
this.setState(CLOSING_STATE);
1700473117
1700473118
break;
1700473119
1700473120
case CLOSING_STATE://电梯是关门状态,则什么都不做
1700473121
1700473122
//do nothing;
1700473123
1700473124
break;
1700473125
1700473126
case RUNNING_STATE://正在运行,门本来就是关闭的,也什么都不做
[
上一页 ]
[ :1.700473077e+09 ]
[
下一页 ]