如何将状态机图表示为UML中的操作的行为? [英] How State machine diagram can be represented as a Behavior for an operation in UML?

查看:144
本文介绍了如何将状态机图表示为UML中的操作的行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

行为(方法主体)可以是状态机或活动-活动易于理解,因为它们等同于过程代码.

Behaviors (Method Body)can be state machines or activities - activities are easy to understand, as they are the equivalent of procedural code.

我不知道如何将状态机用作操作的行为?

能否请您提供一个简单的示例?

---注意---

Operation是仅用于规范的元素-将其想象为OO编程语言中的方法签名.它具有名称和参数列表.

Operation is a specification-only element - imagine it as the method signature in OO programming languages. It has a name and a list of parameters.

行为(除其他外)是操作(或其他行为特征,例如接收)在被调用时所执行的操作-将其想象为方法的主体.

Behavior is (among other things) what an operation (or another behavioral feature such as a reception) does when invoked - imagine it as the body of the method.

推荐答案

只是因为您不能代表您应该这样做".

"Just because you can doesn't mean you should".

换句话说:使用状态模型定义操作的行为可能是合法的-但这并不意味着您应该这样做.我从来没有遇到过一个有用的场景.但这当然并不意味着它们不存在.这也是某些UML规范缺乏内聚力的征兆.

In other words: it may be legal to use a state model to define an operation's behaviour - but it doesn't mean you should. I've never come across a scenario where it would have been useful; but of course that doesn't mean they don't exist. It's also symptomatic of the lack of cohesion in some of the UML specification.

当操作(而不是封闭类)具有状态行为时,这将是适当的.要使用一个真正的示例:考虑方法TcpConnection.close().如果连接已经关闭,则调用close()将无效.如果连接已打开,则调用close()将关闭它.

It would be appropriate where the operation (not the enclosing class) had stateful behaviour. To use a really contrived example: consider a method TcpConnection.close(). If the connection was already closed, then calling close() would have no effect. If the connection was open then calling close() would close it.

[但是:作为示例,它也说明了为什么我从未发现需要特定于方法的状态模型.状态模型实际上属于类,而不是操作].

[However: as an example that also illustrates why I've never found the need for a method-specific state model. The state model really belongs with the class, not the operation].

hth.

这篇关于如何将状态机图表示为UML中的操作的行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆