
UML基本架构建模--关联的术语和概念(二).doc
9页Associations 联联合合An association is a structural relationship that specifies that objects of one thing are connected to objects of another. Given an association connecting two classes, you can relate objects of one class to objects of the other class. It’s quite legal to have both ends of an association circle back to the same class. This means that, given an object of the class, you can link to link to other objects of the same class. An association that connects exactly two classes is called a binary association. Although it’s not as common, you can have associations that connect more than two classes; these are called n-ary associations. Graphically, an association is rendered as a solid line connecting the same or different classes. Use associations when you want to show structural relationships. Beyond this basic form, there are four adornments that apply to associations.联合是一个结构关系,它描述一个事物的对象连接另一个事物的对象.给定一个关联连接两个类,你能建立一个类的对象和另一个类的对象之间的联系.一个联合的一端从一个类出发而另一端又回到这个类的关联是符合规则的.连接两个类的联合被称为二元联合.尽管不是很常见,但是可以有连接超过两个类的联合;这被称为 n级联合.图形显示上,联合表现为一条连接相同或不同的类的实线.在你想显示结构关系时使用联合.除了基本形式,还有四个修饰适用于联合.Name An association can have a name, and you use that name to describe the nature of the relationship. So that there is no ambiguity about its meaning, you can give a direction to the name by providing a direction triangle that points in the direction you intend to read the name, as shown in Figure 5-4.名称:名称:一个联合可以有名称.使用这个名称以描述关系的特征,以便对它的含义没有歧义.你能通过带有方向的三角形给名称提供方向,以指出从哪边开始读名称,如图 5-4 显示的.NoteNote: Although an association may have a name, you typically don’t need to include one if you explicitly provide end names for the association. If you have more than one association connecting the same classes, it is necessary to use either association names or association end names to distinguish them. If an association has more than one end on the same class, it is necessary to use association end names to distinguish the ends. If there is only one association between a pair of classes, some modelers omit the names, but it is better to provide them to make the purpose of the association clear.备注:备注:尽管联合可能有名称,但如果你明确地为联合两端提供名称,那么通常就不需要再包含一个.如果有超过一个联合关联连接同一个类,有必要使用联合名称和联合端名称以示区分,如果一对类之间只有一个联合,有些模型会省略名称,但最好别那么做,以便清晰联合的意图.Role When a class participates in an association, it has a specific role that it plays in that relationship; a role is just the face the class at the far end of the association presents to the class at the near end of the association. You can explicitly name the role a class plays in an association. The role played by an end of an association is called an end name (in UML 1, it was called a role name). In Figure 5-5, the class Person playing the role of employee is associated with the class Company playing the role of employer.角色:角色:当一个类加入到一个联合中,应该有一个特定的角色以使用这个关系;一个角色面对的是联合关联中远端的那个类,代表的是联合关联中近端的这个类.在一个联合关联里,你可以明确地为类的使用者--角色命名.由联合关联的一端扮演的角色被称为端名(在 UML1.0 中,它被称之为角色名).在图 5-5 中,人这个类扮演着职员角色联合到公司这个类所扮演的雇主角色中.NoteNote: The same class can play the same or different roles in other associations.备注:备注:同样的类能在其它的联合中扮演同样的或不同的角色.NoteNote: An attribute may be regarded as a one-way association owned by a class. The attribute name corresponds to the end name on the association end away from the class.备注:备注:属性可以被视为一个类所拥有的单向联合.属性名称与这个联合的端名(离这个类更远的那个端点)一致.Multiplicity An association represents a structural relationship among objects. In many modeling situations, it’s important for you to state how many objects may be connected across an instance of an association. This “how many “ is called the multiplicity of an association’s role. It represents a range of integers specifying the possible size of the set of related objects. It is written as an expression with a minimum and maximum value, which may be the same; two dots are used to separate the minimum and maximum values. When you state a multiplicity at the far end of an association, you are specifying that, for each object of the class at the near end, how many objects at the near end may exist. The number of objects must be in the given range. You can show a multiplicity of exactly one (1), zero or one (0..1), many (0..*), or one or more (1..*). You can give an integer range (such as 2..5). You can even state an exact number (for example, 3, which is equivalent to 3..3).For example, in Figure 5-6, each company object has as employee one or more person objects (multiplicity 1..*); each person object has as employer zero or more company objects (multiplicity *, which is equivalent to 0..*)多多态态:一个:一个联合表示对象之间的结构关系.在大多数的建模情况下,重要的是你要声明多少个对象可以连接一个联合的一个实例.这里的”多少”被称为一个联合角色的多态.它表现为一个整数范围以指定相关对象集的可能大小.被书写为最小值和最大值的表达式,两个值可能一样;用两个小数点将最小值和最大值分开.当你为一个联合的远端那个类表述一个多态性时,你就为近端这个类的每一个对象指定在近端存在多少个对象.对象的数量必须在给定的范围之内.你可以用(1)表示只有一个多态,用(0..1)表示有0个或是一个多态,用(0..*)表示许多,或是(1..*)表示一个或更多.你还可以给定一个整数范围(如2..5),甚至是表达为一个精确的数字(如,3,这等价于3..3).举个例子,在图5-6中显示的,每个公司对象有一个或更多个人对象做为雇员(多态性1..*);每个人对象有0个或多个公司对象做为雇主(多态性 *,等价于0..*).Aggregation A plain association between two classes represents a structural relationship between peers, meaning that。












