关于 UML 类图的问题? [英] Questions about UML class diagrams?

查看:41
本文介绍了关于 UML 类图的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我有几个关于 UML 类图的问题,任何帮助将不胜感激

Hello I have a few questions about UML class diagrams any help will be appreciated

1) 如何在属性中显示指针?

1) How do you show pointers in attributes?

2) 什么是多重性?

3) 组合箭头应该是什么方向?

3) What direction should the composition arrows be?

4) 你如何放置枚举?

4) How do you put enums?

推荐答案

根据当前的 UML 标准 2.4.1 和下一个 2.5(几乎只在更简单的文档中有所不同):

According to the current UML standard 2.4.1 and the next one 2.5 (it differs almost only in more simple documentation):

  • 指针/引用应显示为在引用端带有小黑圈(点)的箭头.如果它不是对象作为属性的指针,但以任何方式计数,都会有没有点的箭头.如果线的两侧都应该有箭头,则可以省略两个箭头.但不是点!如果箭头只有一侧,而你知道,另一侧应该没有箭头,这个空的一端应该用十字标记

在其他事情之前你应该了解

Before other things you should understand

  • 从 A 到 B 的关联显示为 A 和 B 之间的实线.它可以表示一种结构,将 A 的类/实例与 B 的类/实例连接起来.该结构可以是任何类型并且属于任何地方.所有关于线路的信息都描述了这个结构.
  • 如果有两个结构,一个结构将 A 的一个实例与 B 的实例连接起来,另一个结构将 B 的实例与 A 的实例连接起来,您可以在一个关联中显示它们.然后,关于其 B 端的信息描述了第一个结构 (b->a),关于另一端的信息描述了另一个结构.
  • 如果您有多个从 A 到 B 的结构,则必须绘制两种不同的关联.
  • 如果连接结构很复杂,您可以将其表示为关联类.您可以在此处定义更多详细信息.
  • 一个连接结构可以连接两个以上的类,然后它将显示为一个大菱形,并带有这些类的实心分支.还是协会!注意:现有工具对这两个更复杂的关联的支持非常差.你可以很容易地用它们创造一些完全毫无意义的东西.他们很难.小心使用.

  • 多样性.
    • 一个结构的情况:关联两端的多重性表明该结构控制的相邻类的实例数.
    • 两种结构的情况:A-B 关联的 A 端的多重性表明,有多少 A 实例受从 B 到 A 的引导结构控制.它在 B 侧有 0 或 1.另一边的数字属于另一个结构.

    是的,这并不容易,抱歉.但是,更简单"的 2.5 UML 标准的文本要容易得多.简单的解释是错误的,使用它你很快就会在任何实际任务中遇到问题.

    Yes, it is not easy, sorry. But it is MUCH easier, that the text of the "easier" 2.5 UML standard. Easy explanation is a false one, using it you'll quickly run into problems in any real task.

    • 组成和关于它.

    • Composition and about it.

    • 只有一种构图箭头",正如你所说,它被称为黑色或全菱形.当然,它在容器的一侧,而不是.另一个是空菱形,称为共享聚合",或简称为共享".它没有严格定义,您可以使用它创建自己的标准.当然,把它放在物品容器关联的物品一侧是很愚蠢的.但它很容易在关联的两端.
    • 为什么合成钻石只能在一侧?因为组合意味着,只有当存在从容器(或容器本身)引用它们时,项目才存在.当然,这对双方都行不通.
    • 通常您可以看到共享聚合"的名称聚合".这是一个糟糕的错误.因为,根据标准,compositionshared 甚至 none,这三者都是聚合.有人混合使用父项和子项.
    • There are only one composition "arrow", as you called it, it is called black or full diamond. It is on the side of the container, not parent, of course. The other one, empty diamond, is called "shared aggregation", or, shortly, "shared". It is not strictly defined and you can use it creating your own standard. Of course, it would be foolish to put it on the item side of item-container association. But it easily could be on the both ends of association.
    • Why the composition diamond can be only on one side? Because composition means, that items exist ONLY while exist reference to them from the container (or container itself). Of course, that couldn't work for both sides.
    • Often you can see name "aggregation" for "shared aggregation". It is a BAD mistake. Because, according to standard, composition, shared and even none, all three are aggregations. Somebody mixes parent and child terms.

    简单的旧 Enum 很容易 - 它们有一种类块,@MagicMan 说得对.但它们已经过时了.如果你使用更详细的 Java 的枚举类型(当然,其他语言也有),并且你为不同的项目设置不同的字段或函数,你必须为它们使用 class 块,只有你会必须创建您自己的构造型(如果您的工具还没有)并为其设置适当的类块.

    Simple old Enums are easy - there is a sort of class block for them, @MagicMan put it correctly. But they are obsolete already. And if you use more elaborated Java's Enumeration type (surely, other languages have it too), and you set different fields or functions for different items, you have to use class blocks for them, only you'll have to create your own stereotype (if your tool hasn't one already) and set the appropriate class block to it.

    所以,简单的指针是带点的箭头.但是如果存在另一个返回导航,则根本没有箭头,只有点.

    So, simple pointer is arrow with dot. But if there exists another, back navigation, there will be NO arrows at all, and only dot(s).

    在 C++ 中,实例 A 可以不是通过指针而是直接拥有 B 实例.它没有特殊的 UML 符号,它应该以与普通指针属性相同的方式显示.

    In C++ instance A can have the B instance not by pointer, but directly. There is NO special UML sign for it, it should be shown in the same way as normal, pointer attribute.

    这篇关于关于 UML 类图的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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