文档章节

UML中 的各种符号含义

hutaishi
 hutaishi
发布于 2018/08/19 00:59
字数 1163
阅读 12
收藏 0

Class Notation

A class notation consists of three parts:

  1. Class Name
    • The name of the class appears in the first partition.
  2. Class Attributes
    • Attributes are shown in the second partition.
    • The attribute type is shown after the colon.
    • Attributes map onto member variables (data members) in code.
  3. Class Operations (Methods)
    • Operations are shown in the third partition. They are services the class provides.
    • The return type of a method is shown after the colon at the end of the method signature.
    • The return type of method parameters are shown after the colon following the parameter name.
    • Operations map onto class methods in code

Simple class

The graphical representation of the class - MyClass as shown above:

  • MyClass has 3 attributes and 3 operations
  • Parameter p3 of op2 is of type int
  • op2 returns a float
  • op3 returns a pointer (denoted by a *) to Class6

Class Relationships

A class may be involved in one or more relationships with other classes. A relationship can be one of the following types: (Refer to the figure on the right for the graphical representation of relationships).

Relationship Type Graphical Representation

Inheritance (or Generalization):

  • Represents an "is-a" relationship.
  • An abstract class name is shown in italics.
  • SubClass1 and SubClass2 are specializations of Super Class.
  • A solid line with a hollow arrowhead that point from the child to the parent class
Inheritance

Simple Association:

  • A structural link between two peer classes.
  • There is an association between Class1 and Class2
  • A solid line connecting two classes
Simple association

Aggregation:

A special type of association. It represents a "part of" relationship.

  • Class2 is part of Class1.
  • Many instances (denoted by the *) of Class2 can be associated with Class1.
  • Objects of Class1 and Class2 have separate lifetimes.
  • A solid line with a unfilled diamond at the association end connected to the class of composite
Aggregation

Composition:

A special type of aggregation where parts are destroyed when the whole is destroyed.

  • Objects of Class2 live and die with Class1.
  • Class2 cannot stand by itself.
  • A solid line with a filled diamond at the association connected to the class of composite
Composition

Dependency:

  • Exists between two classes if changes to the definition of one may cause changes to the other (but not the other way around).
  • Class1 depends on Class2
  • A dashed line with an open arrow
Dependency

Relationship Names

  • Names of relationships are written in the middle of the association line.
  • Good relation names make sense when you read them out loud:
    • "Every spreadsheet contains some number of cells",
    • "an expression evaluates to a value"
  • They often have a small arrowhead to show the direction in which direction to read the relationship, e.g., expressions evaluate to values, but values do not evaluate to expressions.

Relationship name

Relationship - Roles

  • A role is a directional purpose of an association.
  • Roles are written at the ends of an association line and describe the purpose played by that class in the relationship.
    • E.g., A cell is related to an expression. The nature of the relationship is that the expression is the formula of the cell.

Navigability

The arrows indicate whether, given one instance participating in a relationship, it is possible to determine the instances of the other class that are related to it.

The diagram above suggests that,

  • Given a spreadsheet, we can locate all of the cells that it contains, but that
    • we cannot determine from a cell in what spreadsheet it is contained.
  • Given a cell, we can obtain the related expression and value, but
    • given a value (or expression) we cannot find the cell of which those are attributes.

Visibility of Class attributes and Operations

In object-oriented design, there is a notation of visibility for attributes and operations. UML identifies four types of visibility: publicprotectedprivate, and package.

The +, -, # and ~ symbols before an attribute and operation name in a class denote the visibility of the attribute and operation.

  • + denotes public attributes or operations
  • - denotes private attributes or operations
  • # denotes protected attributes or operations
  • ~ denotes package attributes or operations

Class Visibility Example

Simple Class

In the example above:

  • attribute1 and op1 of MyClassName are public
  • attribute3 and op3 are protected.
  • attribute2 and op2 are private.

Access for each of these visibility types is shown below for members of different classes.

Access Right public (+) private (-) protected (#) Package (~)
Members of the same class yes yes yes yes
Members of derived classes yes no yes yes
Members of any other class yes no no in same package

Multiplicity

How many objects of each class take part in the relationships and multiplicity can be expressed as:

  • Exactly one - 1
  • Zero or one - 0..1
  • Many - 0..* or *
  • One or more - 1..*
  • Exact Number - e.g. 3..4 or 6
  • Or a complex relationship - e.g. 0..1, 3..4, 6.* would mean any number of objects other than 2 or 5

Multiplicity Example

  • Requirement: A Student can take many Courses and many Students can be enrolled in one Course.
  • In the example below, the class diagram (on the left), describes the statement of the requirement above for the static model while the object diagram (on the right) shows the snapshot (an instance of the class diagram) of the course enrollment for the courses Software Engineering and Database Management respectively)

Object Diagram

Aggregation Example - Computer and parts

  • An aggregation is a special case of association denoting a "consists-of" hierarchy
  • The aggregate is the parent class, the components are the children classes

Aggregation Example

Inheritance Example - Cell Taxonomy

  • Inheritance is another special case of an association denoting a "kind-of" hierarchy
  • Inheritance simplifies the analysis model by introducing a taxonomy
  • The children classes inherit the attributes and operations of the parent class.

Inheritance Example

Class Diagram - Diagram Tool Example

A class diagram may also have notes attached to classes or relationships. Notes are shown in grey.

Class Diagram Example

In the example above:

We can interpret the meaning of the above class diagram by reading through the points as following.

  1. Shape is an abstract class. It is shown in Italics.
  2. Shape is a superclass. Circle, Rectangle and Polygon are derived from Shape. In other words, a Circle is-a Shape. This is a generalization / inheritance relationship.
  3. There is an association between DialogBox and DataController.
  4. Shape is part-of Window. This is an aggregation relationship. Shape can exist without Window.
  5. Point is part-of Circle. This is a composition relationship. Point cannot exist without a Circle.
  6. Window is dependent on Event. However, Event is not dependent on Window.
  7. The attributes of Circle are radius and center. This is an entity class.
  8. The method names of Circle are area(), circum(), setCenter() and setRadius().
  9. The parameter radius in Circle is an in parameter of type float.
  10. The method area() of class Circle returns a value of type double.
  11. The attributes and method names of Rectangle are hidden. Some other classes in the diagram also have their attributes and method names hidden.

© 著作权归作者所有

共有 人打赏支持
hutaishi
粉丝 4
博文 63
码字总数 68972
作品 0
广州
程序员
私信 提问
UML类图符号理论

前言 相信大家在学习UML类图的时候,最大的困难可能来自两个方面: 类图中各种关系的区别; 多种关系的符号记忆容易混淆; 本着"Do one thing and do it well."的原则,本文不介绍UML类图中各...

算法与编程之美
2016/02/18
276
3
软考之UML图深入学习(2)

前言 经历过软考之后的UML图学习,对于九种图有了更加深入的认识,上一篇文章《软考之UML图深入学习(1)》中,介绍了UML建模工具是什么? 这篇文章继前文,进一步深入,从小编思考的UML图进...

m18633778874
2017/11/12
0
0
实用UML知识——如何看懂UML传递的软件架构信息

前公司的技术交流大体是靠口授, 个人会采用一些简单的架构文档+ 口述的方式, 描述一个软件产品的整体架构. 并且, 大多数情况是, 先有代码, 后有文档的方式, 这样做有以下优点: 1. 关注软件结...

晨曦之光
2012/03/09
730
0
系统架构师-基础到企业应用架构-系统建模[上篇]

一、摘要 本文主要从系统架构中的建模开始讲解,本文讲述的内容主要是我在工作和学习过程中的总结和经验,不足之处还请大家多多批评指出,有更好的建议也可以留言 说明。本意主旨是为不熟悉系...

wbf961127
2017/11/12
0
0
产品用例怎么写

概念 用例(Use Case)是一种描述产品需求的方法,使用用例的方法来描述产品需求的过程就是用例模型,用例模型是由用例图和每一个用例的详细描述文档所组成的。在技术和产品的工作领域里都有用...

zero2hero
2016/02/17
375
0

没有更多内容

加载失败,请刷新页面

加载更多

《傲慢与偏见》的读书笔记与读后感作文2400字

《傲慢与偏见》的读书笔记与读后感作文2400字: 作者:孙苑馨;笔者按:读书这个习惯是我爸妈养出来的。小时候父母赚的钱除了吃饭穿衣剩下的就是买书了,他们除了买各种新鲜出版的文艺派图书...

原创小博客
13分钟前
0
0
oozie job 的挂了监控报警或重启

oozie Coordinator 的job 和actioni状态很多,但好像不支持设置某状态如failed后30分钟后自动重新拉启,因他的条件只有几种:触发条件可以是一个时间频率、一个dataset实例是否可用,或者可能...

hblt-j
31分钟前
1
0
python精简笔记-[6]-[if,for,while]语句

1.if 条件判断 语法: if 判断条件: 执行语句……elif 判断条件:    执行语句……elif 判断条件:    执行语句……else: 执行语句…… 实例1: n = input("请输...

平头哥-Enjoystudy
35分钟前
0
0
RxJava 是如何实现线程切换的(上)

前言 通过前一篇的从观察者模式出发,聊聊RxJava,我们大致理解了RxJava的实现原理,在RxJava中可以非常方便的实现不同线程间的切换。subscribeOn 用于指定上游线程,observeOn 用于指定下游线...

亭子happy
今天
2
0
想晋级高级工程师只知道表面是不够的!Git内部原理介绍

本文由云+社区发表 作者:腾讯工蜂用户:王二卫 从不一样的视角了解git,以便更好的使用git 一、git & git 版本库认识 git 是一个内容寻址的文件系统,其核心部分是一个简单的键值对数据库(...

腾讯云加社区
今天
2
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部