In software engineering, a class diagram in the Unified Modeling Language (UML) is a type of static structure diagram that describes the structure of a system by showing the system's classes, their attributes, operations (or methods), and the relationships among objects.dom
Diagram provides basic notation for other structure diagrams prescribed by UML
类图为UML规定的其余的结构图提供了符号
Helpful for developers and other team members too
对开发人员是有帮助的,对其余的团队成员一样也有帮助
Business Analysts can use class diagrams to model systems from business perspective
业务分析人员能使用类图从业务角度对系统进行建模
A UML class diagram is made up of: 类图的组成有:学习
A set of classes and(PS: 原文就是这样少了段话)
A set of relationships between classes
类与类之间的一组关系
What is a Class(什么是一个类)
A description of a group of objects all with similar roles in the system, which consists of: 在系统中有类似角色的一组对象的一个描述,其包含:ui
Structural features (attributes) define what objects of the class "know"
结构特征(特性), 定义了类的对象“知道”什么
Represent the state of an object of the class
表明类的一个对象的状态
Are descriptions of the structural or static features of a class
一个类的结构的和静态的特性(特征)的一些描述
Behavioral features (operations) define what objects of the class "can do"
行为特性(操做)定义一个类的一些对象 “能作”什么
Define the way in which objects may interact
定义了类的对象可以以什么样的方式交互
Operations are descriptions of behavioral or dynamic features of a class
操做是一个类的行为的或动态特性的一些描述
Class Notation(类符号)
A class notation consists of three parts: 一个个类由如下三部分组成:lua
Class Name(类名)
类的名字显示在第一部分
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.
在代码中属性映射成为成员变量(数据成员)
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.
返回类型显示在位于方法签名结尾的冒号的后面
Operations map onto class methods in code
在代码中类的操做映射成为方法
The graphical representation of the class - MyClass as shown above: MyClass 类的图形表示如上所示:翻译
MyClass has 3 attributes and 3 operations
MyClass具备3个属性和3个操做/方法
Parameter p3 of op2 is of type int
op2的参数p3 的类型是 int
op2 returns a float
op2 的返回值类型是 float
op3 returns a pointer (denoted by a *) to Class6
op3 返回了一个指向Class6的指针(由 a* 表示)
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).设计
A solid line with a hollow arrowhead that point from the child to the parent class
一个从子类指向父类的带中控箭头的实线
Simple Association(简单关联):
A structural link between two peer classes.
在两个对等的类之间的一个结构的链接
There is an association between Class1 and Class2
Class1 和 Class2 之间存在着一个关联(association)
A solid line connecting two classes
经过一条实线连接两个类
Aggregation(聚合)
A special type of association. It represents a "part of" relationship. 一个特殊的关联关系。 其表明着"part of" 的关系
Class2 is part of Class1.
Class2 是Class1的一部分
Many instances (denoted by the *) of Class2 can be associated with Class1.
Class2的多个实例(由 * 表示) 可以与Class1 关联
Objects of Class1 and Class2 have separate lifetimes.
Class1 的对象和Class2 的对象有各自的生命周期
A solid line with a unfilled diamond at the association end connected to the class of composite
一个在关联的末端带有空心菱形的实线链接到合成的类(译者注: 空心菱形链接到被聚合的类)
Composition(组合)
A special type of aggregation where parts are destroyed when the whole is destroyed. 一种特殊的关联关系,当总体被破坏的时候,部分也被破坏
Objects of Class2 live and die with Class1.
Class2的对象伴随着Class1的对象的死亡而死亡
Class2 cannot stand by itself.
Class2 不可以独立存在
A solid line with a filled diamond at the association connected to the class of composite
一个在关联的末端带有实心菱形的实线链接到合成的类(译者注: 实心菱形链接到被组合的类)
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
Class1 依赖于 Class2
A dashed line with an open arrow
一个带有开放箭头的虚线
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.
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(导航性)
PS:这个标题是实在是不知道怎么翻译是好
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: public, protected, private, and package. 在面向对象设计中, 有一些控制属性和操做/方法的可见性修饰符。 UML肯定了四种可见性修饰符: public、protected、private、*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(类可见性的例子)
In the example above: 上方的例子中:
attribute1 and op1 of MyClassName are public
MyClass类的 attributes1 和 op1 是public的
attribute3 and op3 are protected.
attribute3 和 op3 是 protected
attribute2 and op2 are private.
attribute2 和 op2 是 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 smae package(在同一包下的能够访问)
Multiplicity(多重性)
How many objects of each class take part in the relationships and multiplicity can be expressed as: 每一个类的多少对象参与类之间的关系,多重性能够表示为一下:
Exactly one - 1
刚好是1 - 1
Zero or one - 0..1
0或1 0..1
Many - 0..* or *
多 - 0..* 或者 *
One or more - 1..*
一或多 - 1..*
Exact Number - e.g. 3..4 or 6
肯定的数 - 例如 3..4 或 6
Or a complex relationship - e.g. 0..1, 3..4, 6.* would mean any number of objects other than 2 or 5
或是是一个复杂的关系 - 例如 0--1,3..4,6.* ,意味着除了2和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)
Aggregation Example - Computer and parts(聚合的例子- 电脑和电脑组件)
An aggregation is a special case of association denoting a "consists-of" hierarchy
聚合关系是关联关系的一种特殊的状况,表示一个consists-of(包含)的层级结构
The aggregate is the parent class, the components are the children classes
聚合是父类,组件是子类
Inheritance Example - Cell Taxonomy(继承的例子-单元格分类)
Inheritance is another special case of an association denoting a "kind-of" hierarchy
继承是另外一种特殊的关联关系 表示一种 “kind-of(归类)” 的层级结构
Inheritance simplifies the analysis model by introducing a taxonomy
继承经过引入分类法(taxonomy),简化了分析模型
The children classes inherit the attributes and operations of the parent class.
子类继承父类的属性和方法
Class Diagram - Diagram Tool Example(类图-Diagram Tool Example)
A class diagram may also have notes attached to classes or relationships. Notes are shown in grey. 一个类图也可能有附加到类或者关系上的注释(notes)。 注释一灰色显示。
In the example above: 在上面的例子中
We can interpret the meaning of the above class diagram by reading through the points as following. 经过下面的要点咱们能够理解上面的类图的含义.
Shape is an abstract class. It is shown in Italics.
Shape类是一个抽象类,它以斜体显示
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.
The parameter radius in Circle is an in parameter of type float.
Circle中的 radius(半径) 参数是一个 float 类型的参数
The method area() of class Circle returns a value of type double.
Circle中的 area() 方法的返回值类型是 double 类型
The attributes and method names of Rectangle are hidden. Some other classes in the diagram also have their attributes and method names hidden.
Rectangle的属性和方法名被隐藏了。在该类图中也有一些类具备他们的隐藏的属性和方法
Dealing with Complex System - Multiple or Single Class Diagram?(处理复杂的系统 - 多个或单个类图?)
Inevitably, if you are modeling a large system or a large business area, there will be numerous entities you must consider. Should we use multiple or a single class diagram for modeling the problem? The answer is: 不可避免的,若是你正在建模一个大的系统或者大的业务领域,在这时你必须考虑大量的实体。那么咱们应该使用多个类图仍是单个类图对问题进行建模?答案是:
Instead of modeling every entity and its relationships on a single class diagram, it is better to use multiple class diagrams.
与其将全部的实体和他们之间的关系都建模在单个类图中,使用多个类图是一个更好的选择。
Dividing a system into multiple class diagrams makes the system easier to understand, especially if each diagram is a graphical representation of a specific part of the system.
Perspectives of Class Diagram in Software Development Lifecycle
We can use class diagrams in different development phases of a software development lifecycle and typically by modeling class diagrams in three different perspectives (levels of detail) progressively as we move forward: 咱们可以在软件开发生命周期的不一样的开发阶段使用类图, 一般在咱们不断推动软件开发周期的的过程当中,以三种不一样的视角(粒度的级别)来构建类图:
Conceptual perspective: The diagrams are interpreted as describing things in the real world. Thus, if you take the conceptual perspective you draw a diagram that represents the concepts in the domain under study. These concepts will naturally relate to the classes that implement them. The conceptual perspective is considered language-independent.
Specification perspective: The diagrams are interpreted as describing software abstractions or components with specifications and interfaces but with no commitment to a particular implementation. Thus, if you take the specification perspective we are looking at the interfaces of the software not the implementation.
Implementation perspective: The diagrams are interpreted as describing software implementations in a particular technology and language. Thus, if you take the implementation perspective we are looking at the software implementation.