I use UML Sequence Diagrams all the time, and am familiar with the UML2 notation.
我一直使用UML Sequence Diagrams,熟悉UML2表示法。
But I only ever use them to capture the essence of what I intend to do. In other words the diagram always exists at a level of abstraction above the actual code. Every time I use them to try and describe exactly what I intend to do I end up using so much horizontal space and so many alt/loop frames that its not worth the effort.
但我只是用它们来捕捉我打算做的事情的本质。换句话说,该图总是存在于实际代码之上的抽象级别。每当我使用它们来尝试描述我打算做什么时,我最终会使用如此多的水平空间和如此多的alt / loop帧,这是不值得的。
So it may be possible in theory but has anyone every really used the diagram in this level of detail? If so can you provide an example please?
所以它在理论上可能是有可能的,但是有没有人真正使用过这个细节层次的图表?如果可以,请提供一个例子吗?
6 个解决方案
#1
8
I have the same problem but when I realize that I am going low-level I re-read this:
我有同样的问题,但当我意识到我将进入低级时,我重读了这个:
You should use sequence diagrams when you want to look at the behavior of several objects within a single use case. Sequence diagrams are good at showing collaborations among the objects; they are not so good at precise definition of the behavior.
如果要在单个用例中查看多个对象的行为,则应使用序列图。序列图擅长于显示对象之间的协作;他们并不擅长精确定义行为。
If you want to look at the behavior of a single object across many use cases, use a state diagram. If you want to look at behavior across many use cases or many threads, consider an activity diagram.
如果要查看跨多个用例的单个对象的行为,请使用状态图。如果要查看许多用例或多个线程的行为,请考虑活动图。
If you want to explore multiple alternative interactions quickly, you may be better off with CRC cards, as that avoids a lot of drawing and erasing. It’s often handy to have a CRC card session to explore design alternatives and then use sequence diagrams to capture any interactions that you want to refer to later.
如果你想快速探索多种替代交互,你最好使用CRC卡,因为这样可以避免大量的绘图和擦除。通过CRC卡会话来探索设计备选方案然后使用序列图来捕获您想要稍后引用的任何交互,通常很方便。
[excerpt from Martin Fowler's UML Distilled book]
[Martin Fowler的UML Distilled书摘录]
#2
4
It's all relative. The law of diminishing returns always applies when making a diagram. I think it's good to show the interaction between objects (objectA initializes objectB and calls method foo on it). But it's not practical to show the internals of a function. In that regard, a sequence diagram is not practical to capture the logic at the same depth as code. I would argue for intricate logic, you'd want to use a flowchart.
这都是相对的。收益递减法则在制作图表时始终适用。我认为展示对象之间的交互是好的(objectA初始化objectB并在其上调用方法foo)。但是显示函数的内部结构是不切实际的。在这方面,序列图对于捕获与代码相同深度的逻辑是不实际的。我会争论错综复杂的逻辑,你想要使用流程图。
#3
2
I think there are two issues to consider.
我认为有两个问题需要考虑。
Be concrete
Sequence diagrams are at their best when they are used to convey to a single concrete scenario (of a use case for example).
当序列图用于传达单个具体场景(例如用例)时,它们处于最佳状态。
When you use them to depict more than one scenario, usually to show what happens in every possible path through a use case, they get complicated very quickly.
当您使用它们来描述多个场景时,通常是为了显示通过用例在每个可能路径中发生的事情,它们会很快变得复杂。
Since source code is just like a use case in this regard (i.e. a general description instead of a specific one), sequence diagrams aren't a good fit. Imagine expanding x levels of the call graph of some method and showing all that information on a single diagram, including all if & loop conditions..
由于源代码就像这方面的用例(即一般描述而不是特定描述),序列图不是很合适。想象一下,扩展某种方法的调用图的x级,并在单个图上显示所有信息,包括所有if&loop条件。
That's why 'capturing the essence' as you put it, is so important.
这就是为什么“捕捉本质”就像你说的那样,是如此重要。
Ideally a sequence diagram fits on a single A4/Letter page, anything larger makes the diagram unwieldy. Perhaps as a rule of thumb, limit the number of objects to 6-10 and the number of calls to 10-25.
理想情况下,序列图适合单个A4 / Letter页面,任何更大的图表都会使图表变得笨拙。也许根据经验,将对象数量限制为6-10,将调用次数限制为10-25。
Focus on communication
Sequence diagrams are meant to highlight communication, not internal processing.
序列图旨在突出通信,而不是内部处理。
They're very expressive when it comes to specifying the communication that happens (involved parties, asynchronous, synchronous, immediate, delayed, signal, call, etc.) but not when it comes to internal processing (only actions really)
在指定发生的通信(涉及方,异步,同步,立即,延迟,信号,呼叫等)时,它们非常具有表现力,但在内部处理时却没有表现(仅限于行动)
Also, although you can use variables it's far from perfect. The objects at the top are, well, objects. You could consider them as variables (i.e. use their names as variables) but it just isn't very convenient.
此外,虽然你可以使用变量,但它远非完美。顶部的对象是对象。您可以将它们视为变量(即使用它们的名称作为变量)但它不是很方便。
For example, try depicting the traversal of a linked list where you need to keep tabs on an element and its predecessor with a sequence diagram. You could use two 'variable' objects called 'current' and 'previous' and add the necessary actions to make current=current.next and previous=current but the result is just awkward.
例如,尝试描绘链接列表的遍历,您需要使用序列图来标记元素及其前任的标签。您可以使用两个名为“current”和“previous”的“变量”对象,并添加必要的操作以使current = current.next和previous = current但结果却很尴尬。
#4
1
Personally I have used sequence diagrams only as a description of general interaction between different objects, i.e. as a quick "temporal interaction sketch". When I tried to get more in depth, all quickly started to be confused...
就个人而言,我仅使用序列图作为不同对象之间的一般交互的描述,即作为快速“时间交互草图”。当我试图深入了解时,很快就开始混淆了......
I've found that the best compromise is a "simplified" sequence diagram followed by a clear but in depth description of the logic underneath.
我发现最好的折衷方案是“简化”序列图,然后对下面的逻辑进行清晰但深入的描述。
#5
1
The answer is no - it does capture it better then your source code! At least in some aspects. Let me elaborate.
答案是否定的 - 它确实比你的源代码更好地捕获它!至少在某些方面。让我详细说明一下。
You - like the majority of the programmers, including me - think in source code lines. But the software end product - let's call it the System - is much more than that. It only exists in the mind of your team members. In better cases it also exists on paper or in other documented forms.
你 - 像大多数程序员一样,包括我 - 在源代码行中思考。但是软件最终产品 - 我们称之为系统 - 远不止于此。它只存在于团队成员的脑海中。在更好的情况下,它也存在于纸上或其他形式的文件中。
There are plenty of standard 'views' to describe the System. Like UML Class diagrams, UML activity diagrams etc. Each diagram shows the System from another point of view. You have static views, dynamic views, but in an architectural/software document you don't have to stop there. You can present nonstandard views in your own words, e.g. deployment view, performance view, usability view, company-values view, boss's favourite things view etc. Each view captures and documents certain properties of the System.
有很多标准的“观点”来描述系统。像UML类图,UML活动图等。每个图从另一个角度显示系统。您有静态视图,动态视图,但在架构/软件文档中,您不必停在那里。您可以用自己的语言呈现非标准观点,例如:部署视图,性能视图,可用性视图,公司值视图,老板最喜欢的东西视图等。每个视图都捕获并记录系统的某些属性。
It's very important to realize that the source code is just one view. The most important though because it's needed to generate a computer program. But it doesn't contain every piece of information of your System, nor explicitly nor implicitly. (E.g. the shared data between program modules, what are only connected via offline user activity. No trace in the source). It's just a static view which helps very little to understand your processes, the runtime dynamics of your living-breathing program.
认识到源代码只是一个视图是非常重要的。最重要的是因为它需要生成一个计算机程序。但它不包含您系统的每一条信息,也不包含明确或隐含的信息。 (例如,程序模块之间的共享数据,仅通过离线用户活动连接的内容。源中没有跟踪)。它只是一个静态视图,很难理解你的过程,你的生活呼吸程序的运行时动态。
A classic example of the Observer pattern. Especially if it used heavily, you'll hardly understand the System mechanis from the source code. That's why you use Sequence diagrams in that case. It captures the 'dynamic logic' of your system a lot better than your source code.
Observer模式的典型示例。特别是如果它使用很多,你很难从源代码中理解系统机制。这就是你在这种情况下使用序列图的原因。它比您的源代码更好地捕获系统的“动态逻辑”。
But if you meant some kind of business logic in great detail, you are better off with plain text/source code/pseudocode etc. You don't have to use UML diagrams just because they are the standard. You can use usecase modeling without drawing usecase diagrams. Always choose the view what's the best for you and for your purpose.
但是,如果您非常详细地考虑某种业务逻辑,那么您最好使用纯文本/源代码/伪代码等。您不必仅仅因为它们是标准而使用UML图。您可以在不绘制用例图的情况下使用用例建模。始终选择最适合您和您的目的的视图。
#6
0
U.M.L. diagrams are guidelines, not strictly rules.
U.M.L.图表是指导原则,不是严格的规则。
You don't have to make them exactly & detailed as the source code, but, you may try it, if you want it.
您不必使它们与源代码完全一致,但是,如果您需要,可以尝试使用它。
Sometimes, its possible to do it, sometimes, its not possible, because of the detail or complexity of systems, or don't have the time or details to do it.
有时,由于系统的细节或复杂性,或者没有时间或细节来实现,有时可能会这样做,这是不可能的。
Cheers.
P.D. Any cheese-burguer or tuna-fish-burguer for the cat ?
P.D.猫的任何奶酪 - burguer或金枪鱼 - 鱼 - burguer?
#1
8
I have the same problem but when I realize that I am going low-level I re-read this:
我有同样的问题,但当我意识到我将进入低级时,我重读了这个:
You should use sequence diagrams when you want to look at the behavior of several objects within a single use case. Sequence diagrams are good at showing collaborations among the objects; they are not so good at precise definition of the behavior.
如果要在单个用例中查看多个对象的行为,则应使用序列图。序列图擅长于显示对象之间的协作;他们并不擅长精确定义行为。
If you want to look at the behavior of a single object across many use cases, use a state diagram. If you want to look at behavior across many use cases or many threads, consider an activity diagram.
如果要查看跨多个用例的单个对象的行为,请使用状态图。如果要查看许多用例或多个线程的行为,请考虑活动图。
If you want to explore multiple alternative interactions quickly, you may be better off with CRC cards, as that avoids a lot of drawing and erasing. It’s often handy to have a CRC card session to explore design alternatives and then use sequence diagrams to capture any interactions that you want to refer to later.
如果你想快速探索多种替代交互,你最好使用CRC卡,因为这样可以避免大量的绘图和擦除。通过CRC卡会话来探索设计备选方案然后使用序列图来捕获您想要稍后引用的任何交互,通常很方便。
[excerpt from Martin Fowler's UML Distilled book]
[Martin Fowler的UML Distilled书摘录]
#2
4
It's all relative. The law of diminishing returns always applies when making a diagram. I think it's good to show the interaction between objects (objectA initializes objectB and calls method foo on it). But it's not practical to show the internals of a function. In that regard, a sequence diagram is not practical to capture the logic at the same depth as code. I would argue for intricate logic, you'd want to use a flowchart.
这都是相对的。收益递减法则在制作图表时始终适用。我认为展示对象之间的交互是好的(objectA初始化objectB并在其上调用方法foo)。但是显示函数的内部结构是不切实际的。在这方面,序列图对于捕获与代码相同深度的逻辑是不实际的。我会争论错综复杂的逻辑,你想要使用流程图。
#3
2
I think there are two issues to consider.
我认为有两个问题需要考虑。
Be concrete
Sequence diagrams are at their best when they are used to convey to a single concrete scenario (of a use case for example).
当序列图用于传达单个具体场景(例如用例)时,它们处于最佳状态。
When you use them to depict more than one scenario, usually to show what happens in every possible path through a use case, they get complicated very quickly.
当您使用它们来描述多个场景时,通常是为了显示通过用例在每个可能路径中发生的事情,它们会很快变得复杂。
Since source code is just like a use case in this regard (i.e. a general description instead of a specific one), sequence diagrams aren't a good fit. Imagine expanding x levels of the call graph of some method and showing all that information on a single diagram, including all if & loop conditions..
由于源代码就像这方面的用例(即一般描述而不是特定描述),序列图不是很合适。想象一下,扩展某种方法的调用图的x级,并在单个图上显示所有信息,包括所有if&loop条件。
That's why 'capturing the essence' as you put it, is so important.
这就是为什么“捕捉本质”就像你说的那样,是如此重要。
Ideally a sequence diagram fits on a single A4/Letter page, anything larger makes the diagram unwieldy. Perhaps as a rule of thumb, limit the number of objects to 6-10 and the number of calls to 10-25.
理想情况下,序列图适合单个A4 / Letter页面,任何更大的图表都会使图表变得笨拙。也许根据经验,将对象数量限制为6-10,将调用次数限制为10-25。
Focus on communication
Sequence diagrams are meant to highlight communication, not internal processing.
序列图旨在突出通信,而不是内部处理。
They're very expressive when it comes to specifying the communication that happens (involved parties, asynchronous, synchronous, immediate, delayed, signal, call, etc.) but not when it comes to internal processing (only actions really)
在指定发生的通信(涉及方,异步,同步,立即,延迟,信号,呼叫等)时,它们非常具有表现力,但在内部处理时却没有表现(仅限于行动)
Also, although you can use variables it's far from perfect. The objects at the top are, well, objects. You could consider them as variables (i.e. use their names as variables) but it just isn't very convenient.
此外,虽然你可以使用变量,但它远非完美。顶部的对象是对象。您可以将它们视为变量(即使用它们的名称作为变量)但它不是很方便。
For example, try depicting the traversal of a linked list where you need to keep tabs on an element and its predecessor with a sequence diagram. You could use two 'variable' objects called 'current' and 'previous' and add the necessary actions to make current=current.next and previous=current but the result is just awkward.
例如,尝试描绘链接列表的遍历,您需要使用序列图来标记元素及其前任的标签。您可以使用两个名为“current”和“previous”的“变量”对象,并添加必要的操作以使current = current.next和previous = current但结果却很尴尬。
#4
1
Personally I have used sequence diagrams only as a description of general interaction between different objects, i.e. as a quick "temporal interaction sketch". When I tried to get more in depth, all quickly started to be confused...
就个人而言,我仅使用序列图作为不同对象之间的一般交互的描述,即作为快速“时间交互草图”。当我试图深入了解时,很快就开始混淆了......
I've found that the best compromise is a "simplified" sequence diagram followed by a clear but in depth description of the logic underneath.
我发现最好的折衷方案是“简化”序列图,然后对下面的逻辑进行清晰但深入的描述。
#5
1
The answer is no - it does capture it better then your source code! At least in some aspects. Let me elaborate.
答案是否定的 - 它确实比你的源代码更好地捕获它!至少在某些方面。让我详细说明一下。
You - like the majority of the programmers, including me - think in source code lines. But the software end product - let's call it the System - is much more than that. It only exists in the mind of your team members. In better cases it also exists on paper or in other documented forms.
你 - 像大多数程序员一样,包括我 - 在源代码行中思考。但是软件最终产品 - 我们称之为系统 - 远不止于此。它只存在于团队成员的脑海中。在更好的情况下,它也存在于纸上或其他形式的文件中。
There are plenty of standard 'views' to describe the System. Like UML Class diagrams, UML activity diagrams etc. Each diagram shows the System from another point of view. You have static views, dynamic views, but in an architectural/software document you don't have to stop there. You can present nonstandard views in your own words, e.g. deployment view, performance view, usability view, company-values view, boss's favourite things view etc. Each view captures and documents certain properties of the System.
有很多标准的“观点”来描述系统。像UML类图,UML活动图等。每个图从另一个角度显示系统。您有静态视图,动态视图,但在架构/软件文档中,您不必停在那里。您可以用自己的语言呈现非标准观点,例如:部署视图,性能视图,可用性视图,公司值视图,老板最喜欢的东西视图等。每个视图都捕获并记录系统的某些属性。
It's very important to realize that the source code is just one view. The most important though because it's needed to generate a computer program. But it doesn't contain every piece of information of your System, nor explicitly nor implicitly. (E.g. the shared data between program modules, what are only connected via offline user activity. No trace in the source). It's just a static view which helps very little to understand your processes, the runtime dynamics of your living-breathing program.
认识到源代码只是一个视图是非常重要的。最重要的是因为它需要生成一个计算机程序。但它不包含您系统的每一条信息,也不包含明确或隐含的信息。 (例如,程序模块之间的共享数据,仅通过离线用户活动连接的内容。源中没有跟踪)。它只是一个静态视图,很难理解你的过程,你的生活呼吸程序的运行时动态。
A classic example of the Observer pattern. Especially if it used heavily, you'll hardly understand the System mechanis from the source code. That's why you use Sequence diagrams in that case. It captures the 'dynamic logic' of your system a lot better than your source code.
Observer模式的典型示例。特别是如果它使用很多,你很难从源代码中理解系统机制。这就是你在这种情况下使用序列图的原因。它比您的源代码更好地捕获系统的“动态逻辑”。
But if you meant some kind of business logic in great detail, you are better off with plain text/source code/pseudocode etc. You don't have to use UML diagrams just because they are the standard. You can use usecase modeling without drawing usecase diagrams. Always choose the view what's the best for you and for your purpose.
但是,如果您非常详细地考虑某种业务逻辑,那么您最好使用纯文本/源代码/伪代码等。您不必仅仅因为它们是标准而使用UML图。您可以在不绘制用例图的情况下使用用例建模。始终选择最适合您和您的目的的视图。
#6
0
U.M.L. diagrams are guidelines, not strictly rules.
U.M.L.图表是指导原则,不是严格的规则。
You don't have to make them exactly & detailed as the source code, but, you may try it, if you want it.
您不必使它们与源代码完全一致,但是,如果您需要,可以尝试使用它。
Sometimes, its possible to do it, sometimes, its not possible, because of the detail or complexity of systems, or don't have the time or details to do it.
有时,由于系统的细节或复杂性,或者没有时间或细节来实现,有时可能会这样做,这是不可能的。
Cheers.
P.D. Any cheese-burguer or tuna-fish-burguer for the cat ?
P.D.猫的任何奶酪 - burguer或金枪鱼 - 鱼 - burguer?