哪种UML图适合?两个对象交互,一个正在改变另一个的状态 [英] Which UML Diagram is suitable ? Two object interacting, and one is changing the state of other

查看:32
本文介绍了哪种UML图适合?两个对象交互,一个正在改变另一个的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 我的要求:我想根据下面描述的案例提出一个合适的 UML 图.我需要知道哪种 UML 最适合这种情况.

  • My requirement : I want to come up with a suitable UML diagram based on the case which is described below. I need to know which UML will best suit this condition.

案例:两个对象A和B以应用程序表单"的形式相互交互.对象A中的某个事件触发了对象B的状态变化.两个对象为了一个用例而相互交互.

The case : Two object A and B in the form of "Application Forms" interacts with each other.Certain event in object A triggers a state change of object B.Both object interacts with each other for a Use Case.

我尝试使用状态图,但它失败了,因为这里 2 个对象相互交互以更改一个对象的状态,而状态图仅适用于描述一个对象的状态变化,而不显示与导致状态的另一个对象的交互改变.

I tried using State Diagram but it fails as here 2 object interact with each other to change the state of one object, whereas State diagram is suitable to depict state change of one object only without showing interaction with another object which is causing state change.

我的要求是在同一张图中同时显示交互和状态变化.这可能吗?

My requirement is to show both interaction and state change together in the same diagram.Is it possible?

对此有什么建议适合哪种 UML 图?

Any suggestion on this which UML diagram is suitable for this?

推荐答案

UML 对每种行为使用两种不同的图,一种用于 State (状态机图)和一个交互图(可能是通信图序列图).

UML uses two different diagrams for each behavior, one for State (State Machine Diagram) and one for Interaction (could be the communication diagram or the sequence diagram).

因为类的接口在状态改变时不会改变(例如通过应用状态模式),从调用者的角度来看,交互不应该真正改变,当然,内部可能会发生各种各样的事情,但这应该无关紧要.

Since the Interface of a class doesn't change when it's state changes (by applying the State Pattern for example), the interaction should not really change from the perspective of the caller, sure, internally all kinds of things might be going on, but that should not really matter.

我对此建模的方式是描述您的对象处于哪种状态以及将出现哪种情况.这将导致一些交互和可能的状态更改.然后选择一个新场景,要么使用前一个场景的结束状态作为起点,要么描述一个新的开始状态.

The way I'd model this is to describe which states your objects are in and which scenario will play out. That will result in a few interactions and possibly state changes. Then pick a new scenario, either using the end-state of the previous one as a starting point, or describing a new starting state.

这样每个场景都被明确定义,交互图显示了对象如何交互,多个状态图突出显示活动状态可以显示状态的变化,从而显示不同对象的行为.

That way each scenario is clearly defined, the interaction diagram shows how the objects interact, and multiple State Diagrams with the active state highlighted can show the changes in state and thus behavior of the different objects.

没有图可以优雅地结合两者,因为一个(状态机)是一个静态图,显示所有可能的选项,而另一个描述交互.

There is no diagram that gracefully combines both, since one (the state machine) is a static diagram, showing all possible options, while the other describes the interaction.

当然,您可以按照建议(ObjectA/State)作为交互类型图中的不同对象使用创造性命名,但这不会产生非常清晰的图片.您在这里试图描述的是一个故事、一系列事件以及这些事件如何影响对象的不同状态.因此,您的场景是高层次的故事,通信图表是更详细层次的故事,状态机图表是特定情况的快照.

Sure you could play around with creative naming, as suggested (ObjectA/State) as your different objects in the interaction type diagrams, but it would not result in a very clear picture. What you're trying to describe here is a story, a sequence of events and how those events impact the different states of the objects. So your scenario's are the story on a high level, the communication diagrams the stories on a much more detailed level and the state machine diagram the snapshots of specific situations.

这篇关于哪种UML图适合?两个对象交互,一个正在改变另一个的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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