如何在UML中表示C ++的嵌套类? [英] How to represent the nested class of C++ in UML?

查看:566
本文介绍了如何在UML中表示C ++的嵌套类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在UML中表示C ++的嵌套类?
A类{
B类{
}
}

How to represent the nested class of C++ in UML? class A { class B { } }

推荐答案

I曾经以为规范脱离了十字符号。因此,我在规范中四处徘徊,但在2.0中找不到它。我必须得出的结论是2.0规范不再支持它。尽管实际上是在v1.4中指定的,但我在整个2.4.1规范中一直浏览,却无处可见(实际上, anchor一词在整个文档范围内的搜索结果均为0)。我环顾四周,这就是我可以拼凑的东西。

I had thought that the spec got away from the cross-and-circle notation. So, I did some wandering around in the specs, and couldn't find it in 2.0. I have to conclude that the 2.0 spec no longer supports it. While it's actually specified in v1.4, I looked all through the 2.4.1 spec, and it isn't anywhere to be seen (in fact, the word "anchor" returns 0 results in a document-wide search). I did some other looking around, and here's what I can piece together.

首先,我一直了解嵌套类是实现组合的一种方式。此外,UML尝试与实现无关,而嵌套类并非如此。 (您可以通过其他方式创建合成,并且并非所有的OO语言都支持嵌套类。)现在,1.4的解释包括:

First, I had always understood that nested classes were a means of implementing composition. Furthermore, UML attempts to be implementation-agnostic, and nested classes aren't. (You can create composition in other ways, and not all OO languages support nested classes.) Now, 1.4's explanation includes this:


如果类B通过类A上带有锚点符号的锚点行连接到类A,则在类A的命名空间中声明类B。即,类A和类B之间的关系是命名空间-ownedElement关联。

If Class B is attached to Class A by an "anchor" line with the "anchor" symbol on Class A, then Class B is declared within the Namespace of Class A. That is, the relationship between Class A and Class B is the namespace-ownedElement association.

好。现在,UML 2.0这样说:

Ok. Now UML 2.0 says this:


内核程序包代表了UML的核心建模概念,包括类,关联和程序包。

Kernel package represents the core modeling concepts of the UML, including classes, associations, and packages.

这是内核软件包的示意图:

Here is a diagram of the Kernel package:

这很抽象,但是请看一下NamedElement左上方的抽象类。 ( NamedElement类是具有名称的元素。)请注意,命名空间是从其派生的。现在,请注意,在名称空间类顶部右侧的右侧,还有另一个NamedElement类。其中一个关联具有{subsetsownedElement}属性,并且在Namespace端具有合成菱形。在名称空间端,有{subsets owner}属性。

That's pretty abstruse, but have a look at the NamedElement abstract class at the top left. (A "NamedElement" class is an element that has a name.) Notice that Namespace derives from it. Now, notice on the right, directly to the right of the top of the Namespace class, there's another NamedElement class. One of the associations has the {subsets ownedElement} property on it, and a composition diamond on the Namespace end. On the Namespace end, there is the {subsets owner} property.

这意味着,与Namespace组成关联时,NamedElement是Namespace的子集。换句话说,命名空间和NamedElement之间的关系是1.4规范中描述的namespace-ownedElement关联。因此,组成关系在用命名空间和ownedElement属性进行修饰时,代表嵌套的(或内部的,内部的,或您喜欢的编码语言称呼的)类。

This means that NamedElement, when in composition association with Namespace, is a subset of Namespace. In other words, the relationship between Namespace and NamedElement is the namespace-ownedElement association described in the 1.4 spec. Therefore, the composition relationship, when adorned with the namespace and ownedElement properties, represents a nested (or inner, or internal, or whatever your favorite coding language calls it) class.

因此,我要说的是,如果您使用的是组合符号,这是显示嵌套类的2.0可接受的方式。像这样:

So, I'm going to say that this is the accepted 2.0 way to show nested classes if you are using composition notation. Like this:

现在,另一种方法是将嵌套类粘贴到包含类中。规范中的注释示例未显示此AFAICS,但它们与其他NamedElements(程序包,组件等)一起显示。因此,我不明白为什么不能这样做。

Now, another way is to stick the nested class inside the containing class. The notation examples in the spec don't show this AFAICS, but they show it with other NamedElements (packages, components, etc.) so I don't see why you can't.

但是,我看不到锚符号是最新的。 xmojmr最喜欢的网站(也是一个不错的网站),www.uml-diagrams.org,对此有这样的说法:

However, I don't see that the anchor notation is current. xmojmr's favorite site (and a good site, too), www.uml-diagrams.org, has this to say about it:


现在已淘汰的UML 1.4.2规范将嵌套类定义为在另一个类中声明并属于声明类名称空间的类。这些类之间的关系称为命名空间拥有的元素关联

Now obsolete UML 1.4.2 Specification defined nested class as a class declared within another class and belonging to the namespace of the declaring class. Relationship between those classes was called "namespace owned element association

嵌套分类器,例如嵌套类,嵌套接口或嵌套用例可以像其他任何分类器一样使用,但只能在内部使用

Nested classifier, e.g. nested class, nested interface, or nested use case could be used like any other classifier but only inside the containing class or interface.

每个UML 1.4.2都可以显示一条声明(嵌套)类和一个嵌套类,它们之间由一行连接起来,并带有锚图标。

Per UML 1.4.2 a declaring (nesting) class and a nested class could be shown connected by a line, with an "anchor" icon on the end connected to the declaring class. An anchor icon is a cross inside a circle.

UML 2.x规范-包括最近的UML 2.4.1-描述嵌套注意,在UML 2.4.x的一个示例中,UML的1.4 anchor符号仍在软件包中用作替代成员身份符号,并且未提供任何其他详细信息或说明。

UML 2.x specifications - including the recent UML 2.4.1 - describe nesting of classifiers within structured classes without providing explicit notation for the nesting. Note, that UML's 1.4 "anchor" notation is still used in one example in UML 2.4.x for packages as an "alternative membership notation" and without providing any other details or explanations.

我找不到那个示例图,所以也许它仍然存在。最起码,他的提法似乎已被弃用。我要么使用属性,创建<< nested>> 构造型,要么将嵌套的类放入所有者类中。

I couldn't find that "one example" diagram, so maybe it's still around. But at the very least, the notation seems to be deprecated. I would either use the properties, create a <<nested>> stereotype, or put the nested class inside the owner class.

这篇关于如何在UML中表示C ++的嵌套类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆