有限制地改变状态
我正在研究记录的状态更改实施。例如,当创建记录时,它开始处于“待处理”状态,直到管理员将其状态更改为“活动”、“拒绝”或“撤销”。
问题是,如果状态已从待处理更改为活动状态,则无法将状态更改回待处理或拒绝。已拒绝的状态可以更改回活动状态。
撤销状态不能更改为有效、待定或拒绝。目前我有一系列 if/else 语句来检测这一点,但我想知道是否有更逻辑和标准的方法。
I'm working on a status changing implementation for records. For example, when a record is created, it commences in a 'pending' state until a administrator changes its state to either 'active', 'rejected' or 'revoked'.
The thing is, if a status has been changed from pending to active, the status cannot be changed back to pending or rejected. A rejected status can be changed back to active.
A revoked status cannot changed to active, pending or rejected. At the moment I have a series of if/else statements to detect this but I wondered if there was a more logical and standard approach.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以有一个包含所有允许转换的数组:
你可以做一些更复杂的事情,可以检测如果可以从 A 到 B 并且你可以从 B 到 C,那么你可以从 A 到 C (如果是的话)你想要的东西)。请参阅图论背景下的可达性。
You could have an array with all the allowed transitions:
You could do something a little more complicated that could detect that if can go from A to B and you can go from B to C, then you can go for A to C (if that's something you want). See reachability in the context of graph theory.