Associations (OOM)

来源:互联网 发布:上古卷轴5捏脸数据女 编辑:程序博客网 时间:2024/06/06 19:41

An association represents a structural relationship between classes or between a class and an interface.

An association can be created in the following diagrams:

连接代表类之间、接口之间的层次关系,连接可以由Class Diagram和Composite Structure Diagram创建.

  • Class Diagram
  • Composite Structure Diagram

It is drawn as a solid line between the pair of objects.

用一条实线连接相关的对象

In addition to naming the association itself, you can specify a role name for each end in order to describe the function of a class as viewed by the opposite class. For example, a person considers the company where he works as an employer, and the company considers this person as an employee.

另外你可以对连接进行命名,可以在线端写个角色名描述类函数以使得被连接的类观察的名称.例如:人员对公司的描述是雇主,公司对人员的描述是雇员

Reflexive association  

自连接

A reflexive association is an association between a class and itself.

In the following example, the association Supervise expresses the fact that an employee can, at the same time, be a manager and someone to manage.

自连接是一种类和自身关联的联接.

在下面的例子中:该连接描述了以下情况,一个雇员可以同时是一个经理,是从事管理工作的雇员.

In the Dependencies tab of the class, you can see two identical occurrences of the association, this is to indicate that the association is reflexive and serves as origin and destination for the link.

在类属性的依赖tab中(property sheet),可以看到两个相似的连接,标志这个连接是自连接,为链接的起点和终点服务.

Aggregation 

聚合

An aggregation is a special type of association in which one class represents a larger thing (a whole) made of smaller things (the parts). This is sometimes known as a "has-a" link, and allows you to represent the fact that an object of the whole has objects of the part. In the following example, the family is the whole that can contain children.

聚合是一种特殊的连接,一个大类由小类构成.有时把这当成"拥有一个"链接,可以代表一个物体有其他物体构成了每一部分,在下面的例子中:家庭可以包含小孩

You can create an aggregation directly using the Aggregation tool in the Palette. The aggregation symbol in a diagram is the following:

你可以直接创建一个聚合通过使用聚合的工具在面板上.聚合的标志在类图中的表示如下:

     

Composition 

组合

A composition is a special type of aggregation in which the parts are strongly tied to the whole. In a composition, an object may be a part of only one composite at a time, and the composite object manages the creation and destruction of its parts. In the following example, the frame is a part of a window. If you destroy the window object, the frame part also disappears.

组合是一种特殊的聚合,其中的部分更紧密的联系在一起.在一个组合中,一个物体在同一时间只能成为一个组合的一部分,并且这个组合负责创建和销毁这个物体.在下面的例子中,Frame是Window的一部分,如果你把Window销毁,那么Frame也自动消失.

You can create a composition directly using the Composition tool in the Palette. The composition symbol in a diagram is the following:

你可以创建一个组合通过面板上的组合工具,组合在类图中的标记如下:

        

You can define one of the roles of an association as being either an aggregation or a composition. The Container property needs to be defined to specify which of the two roles is an aggregation or a composition.

你可以定义任何一种连接,聚合或者组合.容器的属性必须被定义为聚合或者组合.