UML实验指导 - 图文 下载本文

1、 讨论并总结在建模过程中运用交互图的重要作用及意义。 2、 消息在交互中扮演什么角色?

3、 假设有一系统的协作图局部如图所示,print方法的功能是将传入的参数的值打印在屏幕上,fact方法是计算阶乘,如果test的初值为1,那么最终将打印出什么?(写出计算过程)

1: print(test)2: *[i=1..3] 1.1: test=test+fact(test):A:B

实验四 类图与包图基础

【实验目的】

(1) 掌握如何创建类; (2) 学习如何为类指定版型; (3) 掌握定义类的职责; (4) 学习分析类的职责; (5) 分析类与包的关系。

【实验性质】

设计性实验。

【实验要求】

(1) (2) (3) (4)

在逻辑视图中创建类;

为创建的类指定相应的类版型; 定义类的职责; 使用类与包。

【实验内容】

本次实验要求能够在用例中加入类,并分析类,发现类的职责。

【实验结果】:(Lab4-1.mdl) 【实验导读】 任务1:创建类

打开Lab4.mdl,在浏览器中展开展开Logical View,在Analysis Mode包中创建以下4个类:

(1) PersonnalPlannerForm ( boundary class) (2) PersonalPlannerController (control class) (3) BuyerRecord (entity class) (4) PlannerProfile (entity class)

注意:类的取名一定要简洁、明了,当类的名字由多个单词构成时,可以由每个单词的首字母构成类名。

图4-1 创建四个类

创建类的步骤:

(1) 右键点击Analysis Mode包,添加类;

(2) 右键点击创建的类,选择Open Specification,在Stereotype选择上述的

相应的类版型;UML中有三种基本的类版型用于分析:边界、实体和控制;

(3) 重复步骤1、2,直到上述的所有类都创建完毕。

任务2:定义类的职责

定义上述创建的4个类的职责。

(1) PersonalPlannerForm //maintain profile

//prompt to create new profile //submit profile information

(2) PersonalPlannerController //maintain profile

//submit profile information

(3) BuyerRecord //find buyer record //create a new record //get e-mail address

(4) PlannerProfile //create a new personal profile //get search criteria

//save home reference to planner //save lender list to profile

具体操作步骤:

(1) 双击PersonalPlannerForm类,打开Specification窗口;

(2) 选择Operation标签,在空白窗口中,鼠标右键点击,选择Insert,输

入上述的相应操作项,得到图4-2; (3) 重复步骤2,为该类添加完所有的操作; (4) 重复1-3直到所有类的操作均添加完毕。

图4-2 输入类的属性

全部类的职责定义完之后得到图4-3。