首页 > 代码库 > UML基本架构建模--关联的通用建模技术(三)

UML基本架构建模--关联的通用建模技术(三)



Modeling Structural Relationships

建模结构关系

 

When you model with dependencies or generalization relationships, you may be modeling classes that represent different levels of importance or different levels of abstraction. Given a dependency between two classes, one class depends on another but the other class has no knowledge of the one. Given a generalization relationship between two classes, the child inherits from its parent but the parent has no specific knowledge of its children. In short, dependency and generalization relationships are asymmetric.

当你用依赖或泛化关系建模时,你可以构建的类代表不同层次的重要性或是不同层次的抽象概念.给定一个在两个类之间的依赖,一个类依赖着另一个类,而这个被依赖的类并不知道有类依赖着它.给定一个两个类之间的泛化关系,子类继承自父类,但父类对它的子类没有具体的了解.总之,依赖和泛化关系是不对称的.

 

When you model with association relationships, you are modeling classes that are peers of one another. Given an association between two classes, both rely on the other in some way, and you can often navigate in either direction. Whereas dependency is a using relationship and generalization is an is-a-kind-of relationship, an association specifies a structural path across which objects of the classes interact.

当你用联合关系建模时,你正在建模的类互相之间是对等的.给定一个连接两个类的联合,两个类在某种方式上互相依赖,你通常可以在两个方向上浏览.依赖是使用关系,泛化是类别关系,而一个联合则是指定类的对象进行交互的结构路径.

 

To model structural relationships,

lFor each pair of classes, if you need to navigate from objects of one to objects of another, specify an association between the two. This is a data-driven view of associations..

lFor each pair of classes, if objects of one class need to interact with objects of the other class other than as local variables in a procedure or parameters to an operation, specify an association between the two. This is more of a behavior-driven view of associations.

lFor each of these associations, specify a multiplicity (especially when the multiplicity is not *, which is the default), as well as role names (especially if they help to explain the model).

lIf one of the classes in an association is structurally or organizationally a whole compared with the classes at the other end that look like parts, mark this as an aggregation by adorning the association at the end near the whole with a diamond.

建模结构关系,

l对于每一对类,如果你需要从其中一个对象导航到另一个对象,那么在两者之间的联系指定为联合.这是联合的数据驱动视图.

l对于每一对类,如果其中一个类的对象需要与另一个类的对象在过程中作为本地的变量或是在操作中作为参数交互,那么在两者之间的联系指定为联合.这更多的是联合的行为驱动视图.

l为这些联合关系的每一个指定多重性(尤其当多重性不是默认的*时),以及角色名称(特别是如果它们有助于解释模型)

l如果一个联合里的一个类与另一端的类相比看起来更象结构或组织整体中的一部分,那么在整体那端修饰上菱形标记为这个关系是聚合.

 

How do you know when objects of a given class must interact with objects of another class? The answer is that CRC cards and use case analysis help tremendously by forcing you to consider structural and behavioral scenarios. Where you find that two or more classes interact using data relationships, specify an association.

你怎么知道给定一个类的对象什么时候必须与另一个类的对象进行交互呢?答案是CRC卡片和用例分析极大的帮助迫使你考虑结构和行为场景.你在哪里找到两个或更多个类存在使用数据交互的关系,就在哪里为它们指定联合.

 

Figure 5-11 shows a set of classes drawn from an information system for a school. Starting at the bottom left of this diagram, you will find the classes namedStudent ,Course, andInstructor. Theres an association between Student andCourse, specifying that students attend courses. Furthermore, every student may attend any number of courses and every course may have any number of students. Similarly, youll find an association betweenCourse andInstructor, specifying that instructors teach courses. For every course there is at least one instructor and every instructor may teach zero or more courses, each course belongs to exactly one department.

在图5-11中显示的来自校园信息系统的一组类.从这个图的左下角开始,你会发现名称为学生课程教师的类.在学生课程之间的联合指出学生选修的课程.此外,每个学生可以选修任意门课程,每门课程可以有任意个学生.同样地,你还会发现在课程教师之间的联合指出教师所教授的课程.每门课程至少有一个教师,每位教师可以教授0门或更多门课程.每门课程完全属于一个院系.

技术分享

 

The relationships betweenSchool and the classesStudent andDepartmentare a bit different. Here youll see aggregation relationships. A school has zero or more students, each student may be a registered member of one or more schools, a school has one or more departments, and each department belongs to exactly one school. You could leave off the aggregation adornments and use plain associations, but by specifying that School is a whole and thatStudent andDepartment are some of its parts, you make clear which one is organizationally superior to the other. Thus, schools are somewhat defined by the students and departments they have. Similarly, students and departments dont really stand alone outside the school to which they belong. Rather, they get some of their identity from their school.

学校学生之间的关系与学校院系之间的关系有点不同.在这里你会看到聚合的关系.一所学校有0个或更多的学生,每个学生可以成为一个或更多的学校的注册会员;一个学校有一个或更多院系,而每个院系完全属于一个学校.你可以不使用聚合修饰而使用普通的联合,但是通过指出学校是一个整体,学生院系是它的一部分,可以使你弄清哪个在组织中处于领导地位.因此学校对学生和院系所拥有的有所限定,学生和院系实际上不能在他们所属学校以外独立存在.相反地,他们从他们的学校获得他们的身份.

 

Youll also see that there are two associations between Departmentand Instructor. One of these associations specifies that every instructor is assigned to one or more departments and that each department has one or more instructors. This is modeled as an aggregation because organizationally, departments are at a higher level in the schools structure than are instructors. The other association specifies that for every department, there is exactly one instructor who is the department chair. The way this model is specified, an instructor can be the chair of no more than one department, and some instructors are not chairs of any department.

你还会看到在院系教师之间有两个联合,这些联合中的一个指定每位教师被分派到一个或多个院系,每个院系有一个或多个教师.这是因为组织性而作为一个聚合建模,院系在学校结构中比教师更高一级.另一个联合为每个院系指定一位教师任系主任.这个模型指定的方式:一位教师可以担任0个或1个院系的主任,任何院系都不能有多位系主任.

 

Note:,Your school might not have departments. You might have chairs who are not instructors, or you might even have students who are also instructors. That doesnt mean that the model here is wrong, its just different. You cannot model in isolation, and every model like this depends on how you intend to use these models.

备注:你的学校也许没有院系,也可能系主任不是教师,甚至有些学生还是教师.这并表示此模型在这些方面有错误,那仅仅是有点不同.你不能孤立的建模,且每个象这样的模型取决于你如何使用这些模型.

 

 

UML基本架构建模--关联的通用建模技术(三)