如何在 UML 中建模递归调用
我想在 UML 中对我的应用程序(用 Python 编写)的函数调用进行建模,但有两个问题。
首先,我尝试绘制序列图,但它是用于对对象的方法调用进行建模,并且我的应用程序是按程序编写的,即我实际拥有的唯一对象是我使用的库(例如 html5lib)中的类型的实例。
第二个问题是有一些递归调用,我需要在 UML 图上对其进行建模,而序列图似乎对此不是一个好的解决方案。
那么我应该使用哪一个 UML 图呢?以及如何对递归调用建模,就像下面的函数一样?
def node_preprocessing(node):
global tags_remove, tags_special
if node.nodeType==3: # Text node
return preprocessing(node.wholeText)
if node.nodeType==1 and node.tagName not in tags_remove: # Tag node
if node.tagName in tags_special:
return tags_special[node.tagName](node)
return convert_tag(node) % u"".join(map(node_preprocessing, node.childNodes))
return u""
另一方面,我不想准确地展示这个函数中发生的所有事情。仅它所调用的内容(本身、预处理(文本)、convert_tag(节点))以及顺序。
附: tags_special 是 lambda 函数的字典。我不需要对他们的通话进行建模。
I want to model function calls of my application (written in Python) in UML and I've two problems.
First is that I've tried to draw sequence diagram, but it is for modeling method calls of objects and my application is written procedurally, i.e. the only objects I actually have are instances of types from libraries I use (e.g. html5lib).
The 2nd issue is that there are some recursive calls, which I need to model on the UML diagram and sequence diagram seems to be bad solution for this.
Which of UML diagrams should I use then? And how to model recursive calls, like in function below?
def node_preprocessing(node):
global tags_remove, tags_special
if node.nodeType==3: # Text node
return preprocessing(node.wholeText)
if node.nodeType==1 and node.tagName not in tags_remove: # Tag node
if node.tagName in tags_special:
return tags_special[node.tagName](node)
return convert_tag(node) % u"".join(map(node_preprocessing, node.childNodes))
return u""
On the other hand I do not want to show exactly everything what happens in this function. Only what it calls (itself, preprocessing(text), convert_tag(node)) and in what order.
ps. tags_special is a dict of lambda functions. I do not need calls of them modeled.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以轻松地对递归调用建模。您甚至不需要拥有对象即可使用序列图。但如果您只对被调用的方法及其顺序感兴趣,我认为最适合的是通信图 http: //en.wikipedia.org/wiki/Communication_diagram 。递归调用可以使用迭代 (*) 进行建模。在序列图中,可以使用循环分区对递归进行建模。
You can easily model recursive calls. You don't even need to have objects to use sequence diagrams. But if you are interested only in called methods and their sequence, I think the best fit would be the communication diagram http://en.wikipedia.org/wiki/Communication_diagram . Recursive calls can be modeled using iteration (*). In sequence diagrams recursion can be modeled using loop partitions.
UML 状态图可能是一个不错的选择。 此示例有一些自反箭头,可能对显示递归有用。
A UML statechart diagram might be a good fit. This example has some reflexive arrows that might be useful for showing recursion.