关系生命周期
@StateMachine static interface ContractLifecycle { @StateSet static interface States { @Initial @Functions({ @Function(transition = ContractLifecycle.Transitions.Activate.class, value = Active.class), @Function(transition = ContractLifecycle.Transitions.Cancel.class, value = Canceled.class) }) static interface Draft {} @Functions({ @Function(transition = ContractLifecycle.Transitions.Expire.class, value = Expired.class), @Function(transition = ContractLifecycle.Transitions.Cancel.class, value = Canceled.class) }) static interface Active {} @End static interface Expired {} @End static interface Canceled {} } @TransitionSet static interface Transitions { static interface Activate {} static interface Expire {} static interface Cancel {} } } @LifecycleMeta(ContractLifecycle.class) public static class Contract extends ReactiveObject { public Contract() { initialState(ContractLifecycle.States.Draft.class.getSimpleName()); } @Transition public void activate() {} @Transition public void expire() {} @Transition public void cancel() {} } // /////////////////////////////////////////////////////////////////////////////// // Relational Case 1. // /////////////////////////////////////////////////////////////////////////////// @StateMachine static interface RelationalOrderLifecycleSharingValidWhile { @StateSet static interface States { @Initial @Function(transition = Transitions.Start.class, value = Started.class) @ValidWhile(on = { ContractLifecycle.States.Active.class }, relation = Relations.Contract.class) static interface Created {} @CompositeState @Function(transition = Transitions.Cancel.class, value = Canceled.class) static interface Started { @StateSet static interface SubStates { @Initial @Function(transition = RelationalOrderLifecycleSharingValidWhile.States.Started.SubTransitions.DoProduce.class, value = Producing.class) @ValidWhile(on = { ContractLifecycle.States.Active.class }, relation = RelationalOrderLifecycleSharingValidWhile.Relations.Contract.class) static interface OrderCreated {} @Function(transition = RelationalOrderLifecycleSharingValidWhile.States.Started.SubTransitions.DoDeliver.class, value = Delivering.class) @ValidWhile(on = { ContractLifecycle.States.Active.class }, relation = RelationalOrderLifecycleSharingValidWhile.Relations.Contract.class) static interface Producing {} @Function(transition = RelationalOrderLifecycleSharingValidWhile.States.Started.SubTransitions.ConfirmComplete.class, value = Done.class) @ValidWhile(on = { ContractLifecycle.States.Active.class }, relation = RelationalOrderLifecycleSharingValidWhile.Relations.Contract.class) static interface Delivering {} @End @ShortCut(RelationalOrderLifecycleSharingValidWhile.States.Finished.class) // Ignoring : @ValidWhile(on = { // ContractLifecycle.States.Active.class }, relation = // Relations.Contract.class) static interface Done {} } @TransitionSet static interface SubTransitions { static interface DoProduce {} static interface DoDeliver {} static interface ConfirmComplete {} } } @End static interface Finished {} @End static interface Canceled {} } @TransitionSet static interface Transitions { static interface Start {} static interface Cancel {} } @RelationSet static interface Relations { @RelateTo(ContractLifecycle.class) static interface Contract {} } } @LifecycleMeta(RelationalOrderLifecycleSharingValidWhile.class) public static class ProductOrderSharingValidWhile extends ProductBase { private Contract contract; public ProductOrderSharingValidWhile(Contract contract) { this.contract = contract; initialState(RelationalOrderLifecycleSharingValidWhile.States.Created.class.getSimpleName()); } @Relation(RelationalOrderLifecycleSharingValidWhile.Relations.Contract.class) public Contract getContract() { return this.contract; } @Transition public void start() {} @Transition public void cancel() {} @Transition public void doProduce() {} @Transition public void doDeliver() {} @Transition public void confirmComplete() {} }
@Test public void test_relational_composite_state_machine_sharing_with_composite_state() { final Contract contract = new Contract(); // Outer Initial State assertState(ContractLifecycle.States.Draft.class, contract); contract.activate(); assertState(ContractLifecycle.States.Active.class, contract); final ProductOrderSharingValidWhile product = new ProductOrderSharingValidWhile(contract); // Outer State + Outer Transition => Composite State => Composite // Initial State { // Outer Initial State assertState(RelationalOrderLifecycleSharingValidWhile.States.Created.class, product); // Outer Transition product.start(); assertState(RelationalOrderLifecycleSharingValidWhile.States.Started.SubStates.OrderCreated.class, product); } { // Composite State + Composite Transition => Composite State product.doProduce(); assertState(RelationalOrderLifecycleSharingValidWhile.States.Started.SubStates.Producing.class, product); product.doDeliver(); assertState(RelationalOrderLifecycleSharingValidWhile.States.Started.SubStates.Delivering.class, product); } { // Composite State + Composite Transition => Composite Final State // => Outer State product.confirmComplete(); assertState(RelationalOrderLifecycleSharingValidWhile.States.Finished.class, product); } }
@Test(expected = LifecycleException.class) public void test_relational_standalone_composite_invalid_state_sharing_from_owning_valid_while() { final Contract contract = new Contract(); assertState(ContractLifecycle.States.Draft.class, contract); final ProductOrderSharingValidWhile order = new ProductOrderSharingValidWhile(contract); try { order.start(); } catch (LifecycleException e) { assertInvalidStateErrorByValidWhile(e, contract, order, ContractLifecycle.States.Active.class); } contract.activate(); assertState(ContractLifecycle.States.Active.class, contract); order.start(); assertState(RelationalOrderLifecycleSharingValidWhile.States.Started.SubStates.OrderCreated.class, order); contract.cancel(); assertState(ContractLifecycle.States.Canceled.class, contract); try { order.doProduce(); } catch (LifecycleException e) { assertInvalidStateErrorByValidWhile(e, contract, order, ContractLifecycle.States.Active.class); throw e; } }
相关推荐
NULL 博文链接:https://barryzhong.iteye.com/blog/1979706
> (3)在基于状态机框架下,您可以快捷地开发嵌入式软件 > (4)充分地发挥状态图的能力,为您实现可自由移植的标准C语言代码 > > UML StateWizard为嵌入式系统开发提供了整套解决方案,包括: > 1)状态图 > 无需...
用图解的方式描述了UML的六中关系,简单明了
有限状态机,(英语:Finite-state machine, FSM),又称有限状态自动机,简称状态机,是表示有限个状态以及在这些状态之间的转移和动作等行为的数学模型。有限状态机体现了两点:首先是离散的,然后是有限的。以下...
网狐客户端源码,用VS2005编译成功 组件结构: 游戏广场; 关系管理; 客户端共享; 头像组件; 下载组件; 信道模块; 游戏等级; 游戏框架
UML和模式应用(原书第3版) 原书名: Applying UML and Patterns : An Introduction to Object-Oriented Analysis and Design and Iterative Development (3rd Edition) 原出版社: Prentice Hall PTR 作者: ...
详细讲解NRF24L01状态机,状态机简写为FSM(Finite State Machine),主要分为2大类:第一类,若输出只和状态有关而与输入无关,则称为Moore状态机;第二类,输出不仅和状态有关而且和输入有关系,则称为Mealy状态机。要...
UML和模式应用(原书第3版) 原书名: Applying UML and Patterns : An Introduction to Object-Oriented Analysis and Design and Iterative Development (3rd Edition) 原出版社: Prentice Hall PTR 作者: ...
UML和模式应用(原书第3版) 原书名: Applying UML and Patterns : An Introduction to Object-Oriented Analysis and Design and Iterative Development (3rd Edition) 原出版社: Prentice Hall PTR 作者: ...
UML和模式应用(原书第3版) 原书名: Applying UML and Patterns : An Introduction to Object-Oriented Analysis and Design and Iterative Development (3rd Edition) 原出版社: Prentice Hall PTR 作者: ...
UML和模式应用(原书第3版) 原书名: Applying UML and Patterns : An Introduction to Object-Oriented Analysis and Design and Iterative Development (3rd Edition) 原出版社: Prentice Hall PTR 作者: ...
UML和模式应用(原书第3版) 原书名: Applying UML and Patterns : An Introduction to Object-Oriented Analysis and Design and Iterative Development (3rd Edition) 原出版社: Prentice Hall PTR 作者: ...
UML和模式应用(原书第3版) 原书名: Applying UML and Patterns : An Introduction to Object-Oriented Analysis and Design and Iterative Development (3rd Edition) 原出版社: Prentice Hall PTR 作者: ...
UML和模式应用(原书第3版) 原书名: Applying UML and Patterns : An Introduction to Object-Oriented Analysis and Design and Iterative Development (3rd Edition) 原出版社: Prentice Hall PTR 作者: ...
Qt的UML工具一般信息: 该工具用于在考虑特定于Qt Framework(插槽/信号/属性等)的情况下创建UML类图。 使用该工具可以创建类图并基于该图生成项目。 该工具可用于快速原型制作和生成样板代码。 请注意,该项目正在...
Cyclus: 一个用于管理具有运行时状态的软件组件的生命周期和依赖关系的小型库
1. 掌握activity组件生命周期函数的用法 2. 掌握使用intent实现activity之间的跳转 3. 掌握在manifest文中定义多个activity,并指定Launcher Activity 4. 掌握Activity的启动模式,和启动模式所对应的Activity和task...
uml客户管理系统课设,基本功能用例图,状态图都画了,当时做的挺用心的
2011-03-24 17:28 169,421 UML六大关系.docx 2011-03-24 17:26 178,061 UML四色原型图.docx 2011-03-24 11:58 103,949 UML图0.docx 2011-03-24 17:27 16,640 UML时间图.docx 2011-03-24 17:29 200,071 UML用例概要....
软件生命周期模型和项目开发过程有非常紧密关系,它是经过多次实践总结出来适合于不同项目使用的经典、有效的软件开发方法,它按照软件生命周期的各个阶段划分任务,依照一定的规则和步骤,有效地进行软件开发。...