在 UML 中,对象的状态机是否定义对象的生命周期?
In UML, does an object's state machine define that object's lifecycle?
That is, do transitions from the initial state to an ordinary state create the object, and transitions to the final state dispose of that object?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说是的 - 至少这可能是最常见的使用方式。
UML 规范中没有强制要求这样做;它允许更普遍地使用状态机。例如,如果状态机具有>1个区域,则最终状态可用于表示区域内行为线程的结束。或者可以使用状态机来定义协议而不是对象的生命周期。
UML 的某些变体(配置文件)确实强制执行您所描述的行为,例如 可执行的 UML。
我可能会反过来问:如果状态机确实定义了对象的生命周期,这对您有用吗?如果是这样,那么就这样使用它。如果您需要形式化,那么您可以定义一个配置文件。但在团队中非正式地达成一致也同样可以。
嗯。
Generally yes - at least that's probably the most common way of using them.
It's not mandated that way in the UML spec; it allows a more general use of state machines. For example, a Final State can be used to signify the end of a behaviour thread within a region if the state machine has >1 regions. Or a state machine can be used to define a protocol instead of an object's lifecycle.
Some variants (profiles) of UML do enforce the behaviour you describe, for example Executable UML.
I'd probably turn the question on its head and ask: would it be useful to you if the state machine did define the object's lifecycle? If so then just use it that way. If you need to formalise then you could define a profile. But it's equally fine to just agree informally in your team.
hth.