State 引入一组表示对象状态的类,然后,把与状态相关的代码逻辑分配到这些类中

语境:

Door
客户代码
重构1,用状态模式简化Door类的状态相关代码。
Door2
DoorState
DoorClosed
DoorClosing
DoorOpen
DoorOpening
DoorStayOpen
重构2,把状态变成常量,每个状态只给出其下一个状态。
Door2
DoorState
DoorClosed
DoorClosing
DoorOpen
DoorStayOpen
DoorOpening
重构3,把状态变成常量,中间对象做为变量传递。
Door2
DoorState
DoorClosed
DoorClosing
DoorOpen
DoorOpening
DoorStayOpen
posted @ 2007-01-10 17:10  南守拥  阅读(271)  评论(0编辑  收藏  举报