使用无状态的基本状态机设置
我有一些相当简单的状态需求(目前)。我想我想使用 Stateless API 来对它们进行建模。 (但我对状态机了解不多,所以我可能是错的。)
但我陷入了术语(特别是状态和触发器)
这里是一个例子:我有一个订单类。它设置有几种状态。它们是:新的、已填充的、运输的、已完成的、已取消的。
我想要的一些简单的状态规则是允许这些状态转换:
- New(是默认值)
- New ->填充
- 新 ->取消
- 已满 ->运输
- 已满 ->取消
- 已满 ->运送
- 运送 ->完成
那么我在这里被绊倒的地方是什么是我的“触发器”?
以防万一需要更具体的示例,假设我想要一个这样的方法:
public bool UpdateOrderStatus(int OrderId, OrderStatusEnum NewOrderStatus)
如果状态更新成功,它将返回 true。如何设置和使用无状态来实现这一点?
I have some fairly simple state needs (for now). I think I would like to model these using the Stateless api. (But I don't really know much about state machines, so I could be wrong.)
But I am getting caught up in the terminology (Specifically State and Trigger)
Here is an example: I have an order class. It is setup with several states. They are: New, Filled, Shipping, Completed, Cancelled.
A few simple state rules I would like is that these state transitions are allowed:
- New (is the default)
- New -> Filled
- New -> Cancelled
- Filled -> Shipping
- Filled -> Cancelled
- Filled -> Shipping
- Shipping -> Complete
So where I am getting tripped up here is what is my "Trigger"?
Just in case a more specific example is needed, say I want a method like this:
public bool UpdateOrderStatus(int OrderId, OrderStatusEnum NewOrderStatus)
that will return true if the status updated successfully. How can setup and use Stateless to make this happen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信,触发器就是这个触发事件。
更新:
当然,触发器名称有时可以等于某些状态名称。
更新:
无状态是非常好的框架!
我已经尝试实现该功能。
状态:
触发器:
订单类:
订单类测试器:
I believe, the trigger is this triggering event.
Update:
Of course trigger name sometimes can be equal to some of state names.
Update:
stateless is really nice framework!
I've tried to implemented the functionality.
States:
Triggers:
Order class:
Tester for Order class: