使用UML,我如何A< Foo >在以下代码中表示?
template< class T >
class A : public T
{
/* ... */
};
class Foo { };
A< Foo > a_foo;
Run Code Online (Sandbox Code Playgroud)
这样的事情(为可怜的ascii艺术......和Jon Skeet道歉)是我的第一个猜测,但我怀疑它是不正确的.
________________
| |
| |
| Foo |
| |
|______________|
/:\ /|\
«bind»(Foo) : |
: | .......
__:____|___: T :
| :.....:
| |
| A |
| |
|______________|
Run Code Online (Sandbox Code Playgroud)
UML 设计者提出了一项建议,但是它还不是标准的一部分。
如果没有任何模板参数,“A”类型的对象“a”可能是这样的:
+--------------------+
| a: A |
+--------------------+
| [+] doSomething(); |
+--------------------+
Run Code Online (Sandbox Code Playgroud)
对象“a”是“a”的模板,类型参数为“Foo”,可以表示如下:
+-----+
+-----------------| Foo |
| +-----+
| a: A |
+--------------------+
| [+] doSomething(); |
+--------------------+
Run Code Online (Sandbox Code Playgroud)
请注意,在 UML 中,当您声明一个类时,它们由一个矩形表示,而特定对象(例如“a”)则由圆角矩形表示。有些人和工具不遵循“圆角”规范。
干杯。