首页 > 代码库 > UML的通用机制(三)

UML的通用机制(三)



Common Divisions

In modeling object-oriented systems, the world often gets divided in several ways.

First, there is the division of class and object. A class is an abstraction; an object is one concrete manifestation of that abstraction. In the UML, you can model classes as well as objects, as shown in Figure 2-19. Graphically, the UML distinguishes an object by using the same symbol as its class and then simply underlying the objects name.

In this figure, there is one class, namedCustomer, together with three objects:Jan(which is marked explicitly as being aCustomerobject), :Customer(an anonymous Customer object), andElyse (which in its specification is marked as being a kind ofCustomerobject, although its not shown explicitly here).

 

Almost every building block in the UML has this same kind of class/object dichotomy. For example, you can have use cases and use case executions, component and component instances, nodes and node instances, and so on.

Second, there is the separation of interface and implementation. An interface declares a contract, and an implementation represents one concrete realization of that contract, responsible for faithfully carrying out the interfaces complete semantics. In the UML, you can model both interfaces and their implementations, as shown in Figure2-20.

In this figure, there is one component namedSpellingWizard.dll that provides (implements) two interfaces,IUnknown andISpelling. It also requires an interface,IDictionary, that must be provided by another component.

Almost every building block in the UML has this same kind of interface/implementation dichotomy. For example, you can have use cases and the collaborations that realize them, as well as operations and the methods that implement them.

Third, there is the separation of type and role. The type declares the class of an entity, such as an object, an attribute, or a parameter. A role describes the meaning of an entity within its context, such as a class, component, or collaboration. Any entity that forms part of the structure of another entity, such as an attribute, has both characteristics: It derives some of its meaning from its inherent type and some of its meaning from its role within its context(Figure 2-21).

 

通用划分

在构建面向对象的系统时,往往被划分为几个方面.

首先,有类和对象的划分.一个类是一个抽象的概念,而一个对象是抽象的具体表现形式.在UML中,你可以与构建类一样的构建对象,如图2-19所示.图形表现上,对象的图形表示与它的类一样,区别在于对象的名称下多了一条下划线.

在这个图中,有一个名为客户的类,三个对象:简(它被明确的标识为客户对象):客户(一个匿名客户对象),和依丽丝(尽管在这里没有明确的显示,但它的格式已经告诉了我们它是一个客户对象).

在UML中几乎所有的构建模块都有类和对象的区分.例如,有用例和执行用例,组件和组件实例,节点和节点实例等等.

其次,还有接口和实现的分离.一个接口只定义声明,而实现则表现这个声明的具体实现,它负责如实地执行这个接口完整的语义.在UML中,你可以构建接口和他们的实现,如图2-20所示.

在这个图中,有一个名为SpellingWizard.dll的组件,它提供两个接口,IUnknownISpelling. 还需要一个名为IDictionary接口,这个接口必需由另一个组件提供.

在UML中几乎所有的构建模块都有接口和实现的区分.例如,有用例和实现这些用例的交互,也有操作和实现这些操作的方法.

第三,类型和角色的区分.类型定义一个实体类,如一个对象,一个属性,或是一个参数.角色描述一个实体在上下文中的含义,如一个类,组件,或是交互.那些组成另一个实体的结构部分的实体,如属性,它们有两个特征:它来源于它内部的部分含义及角色所描述的上下文中的部分含义.如图2-21所示.