WEB开发网
开发学院软件开发Java 演化架构和紧急设计: 使用 DSL 阅读

演化架构和紧急设计: 使用 DSL

 2010-07-27 00:00:00 来源:WEB开发网   
核心提示: 清单 1和 清单 2仅做参考,需要解决的问题是如何表示状态机的配置,演化架构和紧急设计: 使用 DSL(3),这种表示是安装暗格的一种惯用模式,清单 3 展示了状态机基于 Java 的配置: 清单 3. 一个配置选择:Java 代码EventdoorClosed=newEvent("d

清单 1和 清单 2仅做参考。需要解决的问题是如何表示状态机的配置。这种表示是安装暗格的一种惯用模式。清单 3 展示了状态机基于 Java 的配置:

清单 3. 一个配置选择:Java 代码

 Event doorClosed = new Event("doorClosed", "D1CL"); 
 Event drawerOpened = new Event("drawerOpened", "D2OP"); 
 Event lightOn = new Event("lightOn", "L1ON"); 
 Event doorOpened = new Event("doorOpened", "D1OP"); 
 Event panelClosed = new Event("panelClosed", "PNCL"); 
 
 Command unlockPanelCmd = new Command("unlockPanel", "PNUL"); 
 Command lockPanelCmd = new Command("lockPanel", "PNLK"); 
 Command lockDoorCmd = new Command("lockDoor", "D1LK"); 
 Command unlockDoorCmd = new Command("unlockDoor", "D1UL"); 
 
 State idle = new State("idle"); 
 State activeState = new State("active"); 
 State waitingForLightState = new State("waitingForLight"); 
 State waitingForDrawerState = new State("waitingForDrawer"); 
 State unlockedPanelState = new State("unlockedPanel"); 
 
 StateMachine machine = new StateMachine(idle); 
 
 idle.addTransition(doorClosed, activeState); 
 idle.addAction(unlockDoorCmd); 
 idle.addAction(lockPanelCmd); 
 
 activeState.addTransition(drawerOpened, waitingForLightState); 
 activeState.addTransition(lightOn, waitingForDrawerState); 
 
 waitingForLightState.addTransition(lightOn, unlockedPanelState); 
 
 waitingForDrawerState.addTransition(drawerOpened, unlockedPanelState); 
 
 unlockedPanelState.addAction(unlockPanelCmd); 
 unlockedPanelState.addAction(lockDoorCmd); 
 unlockedPanelState.addTransition(panelClosed, idle); 
 
 machine.addResetEvents(doorOpened); 

上一页  1 2 3 4 5 6 7 8  下一页

Tags:演化 架构 紧急

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接