状态模式
商品库存中心有个最基本的需求是减库存和补库存。
定义状态接口:
| 1 | public interface State { | 
定义减库存的状态:
| 1 | public class DeductState implements State { | 
定义补库存状态:
| 1 | public class RevertState implements State { | 
定义 Context 类:
| 1 | public class Context { | 
客户端调用:
| 1 | public class Main { | 
参考
商品库存中心有个最基本的需求是减库存和补库存。
定义状态接口:
| 1 | public interface State { | 
定义减库存的状态:
| 1 | public class DeductState implements State { | 
定义补库存状态:
| 1 | public class RevertState implements State { | 
定义 Context 类:
| 1 | public class Context { | 
客户端调用:
| 1 | public class Main { | 
参考