类可见性可以在 UML 类图上显示吗?

发布于 2024-12-14 03:52:42 字数 157 浏览 0 评论 0原文

类可见性是对象设计的重要组成部分。我在几本 UML 书籍中没有看到任何显示非公共类的示例图,也没有在 Enterprise Architect 等工具中看到显示类可见性的方法。 Enterprise Architect 和其他工具允许您在元模型中设置类可见性,但我还没有找到在图表中显示这一点的方法。

Class visibility is an important part of object design. I have not seen any example diagrams showing non-public classes in several UML books, nor have I seen a way to show class visibility in Enterprise Architect, among other tools. Enterprise Architect and other tools allow you to set the class visibility in the metamodel, but I have yet to see a way to show this in the diagrams.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

梦归所梦 2024-12-21 03:52:42

根据 UML 规范 v2.5 beta 2,不仅 NamedElement 而且 PackageableElement 都具有

来自 p48 的 VisibilityKind 类型的 Visibility 属性:

PackageableElement [抽象类]

..[剪断]..

属性

  • visibility : VisibilityKind [0..1] = public 如果 PackageableElement 由命名空间拥有,则必须指定可见性。默认可见性是公开的。

约束

  • namespace_needs_visibility
    命名空间拥有的 PackageableElement 必须具有可见性。
    inv:可见性 = null 意味着名称空间 = null

但是我还没有找到这种可见性的任何符号指南

According to the UML spec v2.5 beta 2 not only the NamedElement but also the PackageableElement has the attribute Visibility of type VisibilityKind

from p48:

PackageableElement [Abstract Class]

..[snip]..

Attributes

  • visibility : VisibilityKind [0..1] = public A PackageableElement must have a visibility specified if it is owned by a Namespace. The default visibility is public.

Constraints

  • namespace_needs_visibility
    A PackageableElement owned by a Namespace must have a visibility.
    inv: visibility = null implies namespace = null

I haven't found any notation guidelines for this visibility however

抱猫软卧 2024-12-21 03:52:42

在 Eclipse 中,您可以看到图标。我的意思是你有一个绿色的类图标,如果是私有的,那么 ap 就会放在顶部。
如果您选择该选项,则该图标也会在类图中可见。
希望这有帮助。

In Eclipse you have the visibility in the icon. I mean that you have a green class icon and if private then a p is put on the top.
This icon is also visible in the class diagram if you select the option.
Hope this help.

请叫√我孤独 2024-12-21 03:52:42

UML 以与编程语言无关的方式支持元模型和表示中的可见性。

有一个名为 VisbilityKind 的枚举可用于各种地方(请参阅 UML 2.3 superstruction 规范 第 7.3.5.5 节,第 142 页)。

在类图上有多种方法来说明可见性。最常见的是使用“-”表示私有功能,使用“+”表示公共功能。例如:

----------------------------
| Class                    |
|--------------------------|
| +publicAttribute: Type   |
| -privateAttribute: Type  |
|--------------------------|
| +publicMethod()          |
| -privateMethod()         |
----------------------------

参见规范第52页图7.28 / 7.29更多例子。

嗯。

UML supports visibility in a programming language-neutral way, both in the metamodel and in representation.

There's an Enumeration named VisbilityKind that is used in various places (see the UML 2.3 superstructure spec section 7.3.5.5 p142).

On class diagrams there are various ways to illustrate visibility. The most common is to use '-' to represent private features and '+' to represent public. For example:

----------------------------
| Class                    |
|--------------------------|
| +publicAttribute: Type   |
| -privateAttribute: Type  |
|--------------------------|
| +publicMethod()          |
| -privateMethod()         |
----------------------------

See figure 7.28 / 7.29 on p52 of the spec for more examples.

hth.

眼趣 2024-12-21 03:52:42

我认为您需要看看 单向和双向-定向关联

i think you need to have a look at Uni-directional and Bi-directional association

山人契 2024-12-21 03:52:42

我刚刚在 UML 2.4.1 基础设施中查找了它。关于图 10.3 p。 95 你会看到 Class 定义为 Type,它是一个 NamedElement,它是一个 Element。使用可见性包,NamedElement 具有如第 9.21.1 页中定义的可见性。 88,如果它属于命名空间。因此,如果你有可见性,那么类就有可见性。您可以使用 + - # 和 ~ 等常用符号(第 89 页)。

VisualParadigm 可以做到这一点。

I just looked it up in the UML 2.4.1 Infrastructure. On figure 10.3 p. 95 you see Class defined as a Type which is a NamedElement which is an Element. With the visibility package a NamedElement has a visibility as defined in 9.21.1 on p. 88, if it belongs to a namespace. So Class has a visibility if you have visibilities. You can use the usual notations with + - # and ~ (p. 89).

VisualParadigm can do this.

最终幸福 2024-12-21 03:52:42

如果您使用构造型定义类(例如 <>),则可以将形状脚本分配给构造型。如果您指定装饰,则应使用类的默认绘图,并添加您的装饰,这可以根据类的范围属性进行条件限制:

decoration X
{
  if(hasproperty("scope","public"))
    print("P");
}

这会在左上角打印一个 P公共课的。但是,您同样可以使用图标来代替。

不幸的是,我找不到将形状脚本分配给默认非定型类的方法。有人知道该怎么做吗?

If you define your class with a stereotype (say <<class>>) you can then assign a shape-script to the stereotype. If you only specify a decoration, this should use the default drawing for a class, and add your decoration, which can be conditional based on the class's scope property:

decoration X
{
  if(hasproperty("scope","public"))
    print("P");
}

This prints a P in the top-left corner of a public class. However, you could equally have an icon instead.

Unfortunately, I can't find a way of assigning a shape-script to a default non-stereotyped class. Anyone know how to do that?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文