How model statemachine, when state is dependent on a function?

混江龙づ霸主 提交于 2019-12-08 08:32:17

问题


I have a Contract class. The contract is valid 1 Jan 2010 - 31 Dec 2010.

It can be in state Active or Passive, depending on which date I ask the instance for it's state. ex. if I ask 4 July 2010, it's in state Active, but if I ask 1 Jan 2011, it's in state Passive.

Statemachine diagram:

From Start state, which state should it go to next ? I'm thinking a pseudo state "default" with an entry function deciding which state to go to next, and then a substate machine with Active and Passive, and then an End state on removal.

But this seems to complicated for such a trivial problem.

How would you do it ?


回答1:


Hmm, you want either do what you describe, which will allow the Contract to be in invalid (start/end) state when someone tries to use the contact without prior date event, or you can try to add the call to that function in a constructor, so your contract is in proper state right away. There might be other solutions, but you should think about what other events (messages/method calls) can happen on the contract than the date. Some might affect the stae as well. BTW. your solution is not as complicated when you instead of embedding the state machine only connects the start and end to active and passive states.



来源:https://stackoverflow.com/questions/2779922/how-model-statemachine-when-state-is-dependent-on-a-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!