简体   繁体   English

方法参数的UML图

[英]UML diagram for method argument

Let's say I have the following code: 假设我有以下代码:

class A {
public:
    void doSomething(B* b);
}

class B {
}

How would I describe this in a UML diagram? 我将如何在UML图中对此进行描述? My first thought is that A uses B, so there should be a dotted line from A to B. But in some of the school papers (this is a very tiny part of a school assignment report) they seem to use the aggregation symbol (empty diamond and solid line). 我的第一个想法是A使用B,因此从A到B应该有一条虚线。但是在某些学校论文(这是学校作业报告中很小的一部分)中,它们似乎使用了聚合符号(空菱形和实线)。

That doesn't seem right to me - if A actually contained a pointer to B as a member, that seems right. 这对我来说似乎不正确-如果A实际上包含一个指向B作为成员的指针,那似乎是正确的。 But when only some methods use a pointer to B, and don't store it in any member variables, it seems wrong. 但是,当只有某些方法使用指向B的指针并且不将其存储在任何成员变量中时,这似乎是错误的。

What's right here? 这是什么

(I could ask my teachers but they usually take really long to respond to this type of question... and honestly, I trust the collective brain trust of Stackoverflow more :) ) (我可以问我的老师,但他们通常需要很长时间才能回答此类问题……老实说,我更信任Stackoverflow的集体大脑信任:))

You should use a simple dependency between A and B: 您应该在A和B之间使用简单的依赖关系:

在此处输入图片说明

A does just use B as parameter in an operation. A只是在操作中使用B作为参数。 If you have some attribute of type B then you would use an association. 如果您具有某些类型B的属性,则可以使用关联。 Aggregation give only a little extra semantics and you can (/should) leave it out unless you know that you want to transport some specific information. 聚合仅提供了一些额外的语义,除非您知道要传输某些特定信息,否则可以(/应该)将其省略。

There should NOT be any arrow between class A and class B . class A class Bclass B之间不应有任何箭头。 Arrows between classes are used to indicate "associations". 类之间的箭头用于指示“关联”。

An association indicates that the system you are developing stores links of some kind between the instances of the associated types. 关联表示您正在开发的系统在关联类型的实例之间存储某种类型的链接。

Source: Properties of associations on UML class diagrams 来源: UML类图上的关联属性

To capture/represent void doSomething(B* b); 捕获/表示void doSomething(B* b); you might try using activity diagram, for more see this link . 您可以尝试使用活动图,有关更多信息,请参见此链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM