概述
组件图(Component Diagram)描述了软件的各种组件和它们之间的依赖关系。组件图中通常包含3种元素:组件(Component)、接口(Interface)和依赖(Dependency)。每个组件实现一些接口,并使用另一些接口。

组件
组件是定义了良好接口的物理实现单元,是系统中可替换的物理部件。一般情况下,组件表示将类、接口等逻辑元素打包而形成的物理模块。一个组件包含它所实现的一个或多个逻辑类的相关信息,创建了一个从逻辑视图到组件视图的映射。
在UML中,组件用一个左侧带有两个突出小矩形的矩形来表示,如下图:

1、名称
组件的名称是一个字符串,位于组件图的内部。组件的名称有两种:简单名和路径名。通常,UML图中的组件只显示其名称,但是也可以用标记值或表示组件细节的附加栏加以修饰。

2、组件的种类
有3种类型的组件:配置组件(Deployment Component)、工作产品组件(Work product
component)和执行组件(Execution Component)
(1)、配置组件是运行系统需要配置的组件,是形成可执行文件的基础。操作系统、Java虚拟机和数据库管理系统都属于配置组件。
(2)、工作产品组件包括模型、源代码和用于创建配置组件的数据文件,它们是配置组件的来源。工作产品组件包括UML图、Java类和JAR文件、动态链接库(dll)和数据库表等。
(3)、执行组件是在运行时创建的组件,是最终可运行的系统产生的允许结果。EJB、Servlets、HTML和XML文档、COM+和.Net组件以及CORBA组件都是执行组件的例子。
3、Rose中不同类型组件的图标表示
(1)、组件
Rose中的组件即一般意义上的组件。也可以用构造型来指定组件类型(如ActiveX、Applet、Application、DLL和Executable等)。如图所示

(2)、子程序规范
子程序规范(Subprogram Specification)通常是一组子程序集合名,子程序中不包括类定义。下图给出了两种表示子程序规范的图标:

(3)、子程序体
下图给出了两种表示子程序体的图标:

(4)、主程序
主程序是包含程序根的文件。

(5)、包规范
包是类的实现方法。包规范(Package Specification)是类的头文件,包含类中函数的原型信息。在C++中,包规范就是.h文件。

(6)、包体
包体(Package Body)包含类操作代码。在C++中,包体就是.cpp文件。

(7)、任务规范
任务表示具有独立控制线程的包。可执行文件通常表示为扩展名为.exe的任务规范。

(8)、任务体
下图是两种表示任务体的图标。

(9)、数据库
数据库可能含有一个或几个结构。

(10)、虚包
下图是两种表示虚包的图标。

(11)、虚子程序
下图是两种表示虚子程序的图标。

接口
接口和组件之间的关系分为两种:实现关系(Realization)和依赖关系(Dependency)。接口和组件之间用实线连接表示实现关系,用虚线连接表示依赖关系。


组件的接口分为两种:导入接口和导出接口。其中导入接口供访问操作的组件使用,导出接口由提供操作的组件提供。上图中,接口对于组件Component是导出接口,对于组件Component2来说是导入接口。
依赖关系
组件图用依赖关系表示各组件之间存在的关系类型。组件图中的依赖关系是由客户指向提供者的虚线箭头。客户组件依赖于提供者组件,提供者组件只在开发时存在,运行时则不存在。

|