我该如何着手实施一个奇怪的 "class" 符号

How do I go about implementing a strange "class" notation

我正在用 C++ 编写一个过度设计的矩阵计算器,但不知道这意味着什么:

我以前从未在 class 图表中见过类似 Valuation = std::map 的框,也不知道要查找什么。我是把它写成构造函数还是什么? 为什么 IntElement 和 Valuation 之间没有联系,即使 IntElement 明明在使用它?

我现在在 header 中有这个是图表要找的吗?

class Valuation{

    Valuation(std::map<char,int>);

};

如果没有更多的上下文,很难说这条线会去哪里,但是 Valuation 框看起来像它请求这样一行:

using Valuation = std::map<char,int>;

即定义Valuation为某个地图的别名。基于 "reasonable" 设计,我希望此行进入 VariableElementIntElement 的共同父 class,可能作为受保护的 typedef。但是,我在图表中看不到任何提示。

我没有看到足够的上下文来猜测为什么没有从 IntElementValuation 的 "uses" 行。考虑到 evaluate 成员,IntElementVariableElement 在这方面似乎处于平等地位。另一方面,我会质疑为什么现有线路连接到 VariableElement 而不是连接到应该定义别名的假设共同父级。这可能是图表作者要提出的问题。 (有时候人会犯错,教授也不例外。)

附录: 我想到了 IntElement::evaluateVariableElement::evaluate 之间的区别。可能是前者忽略了它的参数,因此它并没有真正使用 Valuation 除了类型的名称。另一方面,后者可能会在映射中查找一个条目,因此实现需要 Valuation 是一个完整的类型。这是一个可能的动机,尽管我发现这样的实现细节影响 class 图是值得怀疑的。

让我们看看 UML 2.5 规范是怎么说的。

9.2.4.1 分类器 (第 99 页)

The default notation for a Classifier is a solid-outline rectangle containing the Classifier’s name, and with compartments separated by horizontal lines below the name. The name of the Classifier should be centered in boldface. For those languages that distinguish between uppercase and lowercase characters, Classifier names should begin with an uppercase character.

我在 UML 规范中找不到任何将名称限制为任何给定的 (unicode) 字符集的地方。也许是因为您需要另一本书。所以我们可以从上面得到的是

Valuation = std::map<char,int>

是一个标识符,与例如

的方式相同

wiec8736b(/&& 3l?!blurb

将是一个(奇怪的)标识符。但绝不是一些运算符子句,您可以在其中将字符 = 解释为赋值或相等。

tl;dr 这是垃圾。去问作者他的意思。告诉他要么使用注释和易于理解的文本描述,要么坚持使用有效的 UML 符号。


附带说明:该 UML 图的作者在操作部分中使用了未定义的符号。

9.6.4 表示法 (第 115 页)

If shown in a diagram, an Operation is shown as a text string of the form:

[<visibility>] <name> ‘(‘ [<parameter-list>] ‘)’ 
   [‘:’ [<return-type>] [‘[‘ <multiplicity-range> ‘]’] 
   [‘{‘ <oper-property> [‘,’ <oper-property>]* ‘}’]]

where:

  • <visibility> is the visibility of the Operation (see 7.4).

    <visibility> ::= ‘+’ | ‘-‘ | ‘#’ | ‘~’

/ 是没有定义的可见性。很可能作者将使用 // 作为评论的自由。这可能是可以接受的,但它不会呈现有效的 UML。

作为第二个旁注:n*n 右上角看起来也很可疑。它可能是多重的,并且在这种格式下也是无效的。但这只是猜测。