![](/img/trans.png)
[英]How to show the relationship between a class and another class that takes the instance of the class's instance as an input with a sequence diagram?
[英]How to represent the relationship between an instance of a class and the class that gets it as an input?
我有一个名为House
的 class 。 这个 class 的实例是house
。
class House:
def __init__(self, height, length):
self.height = height
self.length = length
def housePlan():
houseHeight = self.height
houseEdgeLength = self.length
house = House(height,length)
我还有另一个名为Person
的 class 。 这个 class 有几个输入,包括一个House
的实例。
class Person:
def __init__(self,name, house):
self.name = name
self.house = house
问题编辑:我想向观众展示我的程序,我如何用图表展示这些关系?
我还有另一个名为 Person 的 class。 这个 class 有几个输入,包括一个 House 的实例
House的实例不仅在Person的构造函数的参数中给出,而且是 class ( self.house = house
) 的属性,所以:
我说名字是一个很可能的字符串。
所有属性/属性/操作都是公开的,以遵守 Python 规则。
在 class 图的级别,无法看到操作的 arguments 来自何处,因为您可以使用交互(例如,在您的下一个问题中的序列图,我也给出了答案)或活动
(奇怪的是你的房子有长度但没有宽度,所以必须是正方形)
不过,有很多方法可以展示你所拥有的。 无论如何,这是一个可行的方法。
基本上你应该在 class 图中只显示 static 类。 这表明它们是如何相关的。 由于只有House
和Person
,因此在单个图表上绘制它们应该不难。 当事情变得更复杂时,您可能需要更多图表来显示子域。
现在是问题的“输入”部分:这里最好创建一个序列图来显示如何创建实例并在消息参数中传递。 为了显示不同的场景,您将为每个场景创建一个额外的 SD。 你不应该过度使用细节。 即:避免图形化编程。 只需显示足够的内容即可获得良好的概述。
可以在单个对象/类图上半静态地显示实例和类。 但这很少有道理。 因此,如上所述,您应该只使用带有 SD 的 go。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.