首页计算机计算机软件面向对象软件工程 07 第七讲 Analysis and Design with UML.pptx

07 第七讲 Analysis and Design with UML.pptx

页数:60页文件大小:962.0 KB来源: 面向对象软件工程ppt课件

本课件以ESU大学课程注册系统为贯穿案例,先说明可视化建模在捕捉业务过程、沟通、管理复杂性、定义架构与促进复用五方面的价值,随后按UML建模流程依次演示执行者与用例、事件流文档、顺序图与合作图、类的属性操作与关联聚集依赖关系、多重性导航与继承、状态转移图、构件图与配置图,最后系统介绍风险驱动的迭代式开发过程及其各阶段活动。

第七章封面页,标示本章主题为使用UML进行分析与设计
本章议程页,列出可视化建模的好处、UML建模与迭代开发过程三节
什么是可视化建模页,说明其用标准图形符号捕捉系统的本质部分
查看本课件的文字版(共 60 页,供检索与复制)

第1页:第七章基于UML的分析与设计封面

第七章 Analysis and Design with UML(基于 UML 的分析与设计):本章讲解可视化建模的价值、如何用 UML 进行可视化建模,以及迭代式开发过程。

第2页:本章议程

Agenda(本章议程):

  • 7.1 Benefits of Visual Modeling(可视化建模的好处)
  • 7.2 Visual Modeling with UML(用 UML 进行可视化建模)
  • 7.3 The Iterative Development Process(迭代式开发过程)

第3页:什么是可视化建模

7.1 可视化建模的好处 —— 什么是可视化建模:

  • Visual Modeling is modeling using standard graphical notations(可视化建模是使用标准图形符号进行建模)
  • 示例:以 Computer System 表示 Business Process 中的 Order、Item、Ship via 等要素
  • Dr. James Rumbaugh:Modeling captures essential parts of the system(建模捕捉系统的本质部分)

第4页:可视化建模捕捉业务过程

可视化建模捕捉业务过程:Use Case Analysis is a technique to capture business process from user's perspective(用例分析是一种从用户视角捕捉业务过程的技术)。

第5页:可视化建模是沟通工具

Visual Modeling is a Communication Tool(可视化建模是沟通工具):

  • Use visual modeling to capture business objects and logic(用可视化建模捕捉业务对象与逻辑)
  • Use visual modeling to analyze and design your application(用可视化建模分析和设计你的应用)

第6页:可视化建模管理复杂性

Visual Modeling Manages Complexity(可视化建模管理复杂性):通过分层、分视图的模型表达,把复杂的系统分解为可理解、可管理的部分。

第7页:可视化建模定义软件架构

Visual Modeling Defines Software Architecture(可视化建模定义软件架构):

  • User Interface(Visual Basic、Java)
  • Business Logic(C++、Java)
  • Database Server(C++ & SQL)
  • Model your system independent of implementation language(对系统建模独立于实现语言)

第8页:可视化建模促进复用

Visual Modeling Promotes Reuse(可视化建模促进复用):多个系统 Multiple Systems 可以共用同一批可复用构件 Reusable Components。

第9页:UML的概念与用途

7.2 用 UML 进行可视化建模 —— UML Concepts(UML 概念):UML 可用于:

  • Display the boundary of a system & its major functions using use cases and actors(用用例和执行者显示系统边界与主要功能)
  • Illustrate use case realizations with interaction diagrams(用交互图说明用例实现)
  • Represent a static structure of a system using class diagrams(用类图表示系统的静态结构)
  • Model the behavior of objects with state transition diagrams(用状态转移图建模对象行为)
  • Reveal the physical implementation architecture with component & deployment diagrams(用构件图和配置图揭示物理实现架构)
  • Extend your functionality with stereotypes(用版类扩充功能)

第10页:课程注册系统需求描述

Putting the UML to Work(把 UML 用起来)—— ESU University 课程注册系统需求:

  • The Registrar sets up the curriculum for a semester;One course may have multiple course offerings(教务员为一学期设置课程,一门课可有多个课程班)
  • Students select 4 primary courses and 2 alternate courses(学生选 4 门主修课和 2 门备选课)
  • Once a student registers for a semester, the billing system is notified so the student may be billed(注册后通知计费系统以便学生缴费)
  • Students may use the system to add/drop courses for a period of time after registration(注册后一段时间内学生可增删课程)
  • Professors use the system to receive their course offering rosters(教师通过系统获取课程班名单)
  • Users of the registration system are assigned passwords which are used at logon validation(用户分配口令用于登录校验)

第11页:执行者

Actors(执行者):An actor is someone or some thing that must interact with the system under development(执行者是与待开发系统必须交互的人或事物)。课程注册系统中的执行者包括 Student(学生)、Registrar(教务员)、Professor(教师)、Billing System(计费系统)。

第12页:用例

Use Cases(用例):A use case is a pattern of behavior the system exhibits,each use case is a sequence of related transactions performed by an actor and the system in a dialogue(用例是系统展现的行为模式,是执行者与系统在对话中执行的一系列相关事务)。

  • Registrar — maintain the curriculum(维护课程)
  • Professor — request roster(请求名单)
  • Student — maintain schedule(维护课表)
  • Billing System — receive billing information from registration(接收计费信息)

第13页:记录用例:事件流文档

Documenting Use Cases(记录用例):A flow of events document is created for each use case,written from an actor point of view,details what the system must provide to the actor when the use case is executed(为每个用例创建事件流文档,从执行者视角编写,说明用例执行时系统必须向执行者提供什么)。典型内容包括:

  • How the use case starts and ends(用例如何开始与结束)
  • Normal flow of events(正常事件流)
  • Alternate flow of events(备选事件流)
  • Exceptional flow of events(异常事件流)

第14页:维护课程用例的事件流

Maintain Curriculum Flow of Events(维护课程用例的事件流):

  • 用例始于教务员登录注册系统并输入口令,系统校验口令有效(E-1)并提示选择当前或未来学期(E-2)
  • 系统提示教务员选择活动:ADD、DELETE、REVIEW 或 QUIT
  • 选择 ADD 则执行 S-1:Add a Course 子流;选择 DELETE 则执行 S-2:Delete a Course 子流
  • 选择 REVIEW 则执行 S-3:Review Curriculum 子流;选择 QUIT 则用例结束

第15页:课程注册系统用例图

Use Case Diagram(用例图):用例图用来可视化执行者与用例之间的关系。图中 Student、Registrar、Professor、Billing System 四个执行者分别与 Maintain Schedule、Maintain Curriculum、Request Course Roster 等用例相关联。

第16页:用例的uses与extends关系

Uses and Extends Use Case Relationships(用例的使用与扩展关系):

  • A uses relationship shows behavior that is common to one or more use cases(使用关系表示一个或多个用例共有的行为)
  • An extends relationship shows optional behavior(扩展关系表示可选行为)
  • 示例:Register for courses 与 Maintain curriculum 均《uses》Logon validation(登录校验)

第17页:用例实现

Use Case Realizations(用例实现):

  • The use case diagram presents an outside view of the system(用例图呈现系统的外部视图)
  • Interaction diagrams describe how use cases are realized as interactions among societies of objects(交互图描述用例如何由对象群体之间的交互实现)
  • 两类交互图:Sequence diagrams(顺序图)、Collaboration diagrams(合作图)

第18页:选课顺序图

Sequence Diagram(顺序图):顺序图按时间顺序展示对象之间的交互。示例给出 student、registration form、registration manager、math 101、math 101 section 1 之间的消息序列:1: fill in info、2: submit、3: add course(joe, math 101)、4: are you open?、5: are you open?、6: add (joe)、7: add (joe)。

第19页:选课合作图

Collaboration Diagram(合作图):合作图围绕对象及其之间的链接组织对象交互。示例给出 : Registrar、course form : CourseForm、theManager : CurriculumManager、aCourse : Course 之间的消息:1: set course info、2: process、3: add course、4: new course。

第20页:类图概述

Class Diagrams(类图):类图展示系统逻辑视图中类的存在及其关系。类图中的 UML 建模元素包括:

  • Classes and their structure and behavior(类及其结构与行为)
  • Association、aggregation、dependency 与 inheritance 关系
  • Multiplicity and navigation indicators(多重性与导航指示)
  • Role names(角色名)

第21页:类的概念与命名

Classes(类):

  • A class is a collection of objects with common structure, common behavior, common relationships and common semantics(类是具有共同结构、行为、关系和语义的对象集合)
  • Classes are found by examining the objects in sequence and collaboration diagram(通过考察顺序图与协作图中的对象发现类)
  • A class is drawn as a rectangle with three compartments(类画成含三个分栏的矩形)
  • 类应使用领域词汇命名:命名规范建议所有类为首字母大写的单数名词

第22页:课程注册系统的候选类

Classes(类):课程注册系统中识别出的类包括 RegistrationForm、RegistrationManager、Course、Student、CourseOffering、Professor、ScheduleAlgorithm。

第23页:操作

Operations(操作):The behavior of a class is represented by its operations;operations may be found by examining interaction diagrams(类的行为由其操作表示,可通过考察交互图发现操作)。示例:交互图中消息 3: add course(joe, math 01) 对应 RegistrationManager 的 addCourse(Student, Course) 操作。

第24页:属性

Attributes(属性):The structure of a class is represented by its attributes;attributes may be found by examining class definitions, the problem requirements, and by applying domain knowledge(类的结构由其属性表示,可通过考察类定义、问题需求并应用领域知识发现属性)。示例:Each course offering has a number, location and time,故 CourseOffering 含 number、location、time 三个属性。

第25页:类图:属性与操作

Classes(类图:属性与操作):图中给出 RegistrationForm、RegistrationManager(addStudent(Course, StudentInfo))、Course(name、numberCredits、open()、addStudent(StudentInfo))、Student(name、major)、CourseOffering(location、open()、addStudent(StudentInfo))、Professor(name、tenureStatus)、ScheduleAlgorithm 等类。

第26页:关系概述

Relationships(关系):

  • Relationships provide a pathway for communication between objects(关系为对象之间的通信提供通路)
  • 考察顺序图和/或协作图以确定对象之间需要哪些链接:if two objects need to talk,there must be a link between them
  • 三类关系:Association(关联)、Aggregation(聚集)、Dependency(依赖)

第27页:关联、聚集与依赖

Relationships(关系详解):

  • 关联:类之间的双向连接,用连接相关类的实线表示
  • 聚集:整体与其部分之间更强的关系,用带菱形的线表示,菱形靠近表示整体的类
  • 依赖:更弱的关系,表示客户与供应者之间的关系,客户对供应者没有语义知识,用从客户指向供应者的虚线表示

第28页:从交互图发现关系

Finding Relationships(发现关系):通过考察交互图发现关系——If two objects must talk,there must be a pathway for communication。示例:RegistrationManager 向 Math 101:Course 发送 3: add student(joe) 消息,故 RegistrationManager 与 Course 之间存在关联。

第29页:课程注册系统类图

Relationships(关系图):图中给出 RegistrationForm、RegistrationManager、Course、Student、CourseOffering、Professor、ScheduleAlgorithm 之间的关联连线,并标注各类的属性与操作。

第30页:多重性与导航

Multiplicity and Navigation(多重性与导航):

  • Multiplicity defines how many objects participate in a relationship(多重性定义参与关系的对象数量),是一个类的实例相对于另一个类的一个实例的数量
  • 对于每个关联和聚集,关系两端各有一个多重性决策
  • 关联与聚集默认双向,但通常需要限制导航为单向,此时加箭头指示导航方向

第31页:多重性标注示例

Multiplicity and Navigation(多重性标注示例):图中在 RegistrationForm、RegistrationManager、Course、Student、CourseOffering、Professor、ScheduleAlgorithm 之间的关联两端标注多重性,如 1、0..*、1..*、4、3..10、0..4 等。

第32页:继承

Inheritance(继承):

  • Inheritance is a relationship between a superclass and its subclasses(继承是父类与其子类之间的关系)
  • 发现继承的两种途径:Generalization(泛化)与 Specialization(特化)
  • Common attributes, operations, and/or relationships are shown at the highest applicable level in the hierarchy(公共属性、操作和/或关系显示在层次结构中最合适的上层)

第33页:继承示例

Inheritance(继承示例):图中将 Student、Professor 的公共部分上提,引入父类 RegistrationUser(含 name 属性),Course、CourseOffering、RegistrationForm、RegistrationManager、ScheduleAlgorithm 等类保持原有关系。

第34页:对象的状态

The State of an Object(对象的状态):状态转移图展示:

  • The life history of a given class(给定类的生命历史)
  • The events that cause a transition from one state to another(导致状态转移的事件)
  • The actions that result from a state change(状态改变引发的动作)
  • 状态转移图仅为具有显著动态行为的对象创建

第35页:课程班状态转移图

State Transition Diagram(状态转移图):示例给出课程班的 Initialization、Open、Closed、Canceled 四个状态:

  • Open:entry: Register student、exit: Increment count
  • Closed:do: Finalize course;Canceled:do: Notify registered students;Initialization:do: Initialize course
  • 转移:Add Student / Set count = 0;Add student [count < 10]、[count = 10];Cancel 分别转移至 Canceled 与 Closed

第36页:构件图

The Physical World(物理世界):

  • Component diagrams illustrate the organizations and dependencies among software components(构件图说明软件构件之间的组织与依赖)
  • 构件可以是:A source code component(源代码构件)、A run time component(运行时构件)或 An executable component(可执行构件)

第37页:课程注册系统构件图

Component Diagram(构件图):示例给出 Course.dll(含 Course、CourseOffering)、People.dll(含 Student、Professor)、CourseUser、Register.exe、Billing.exe、BillingSystem 等构件及其依赖关系。

第38页:部署系统

Deploying the System(部署系统):

  • The deployment diagram shows the configuration of run-time processing elements and the software processes living on them(配置图展示运行时处理元素的配置及运行其上的软件进程)
  • The deployment diagram visualizes the distribution of components across the enterprise(配置图可视化构件在企业范围内的分布)

第39页:课程注册系统配置图

Deployment Diagram(配置图):示例给出 Registration Server、Database Server 两个服务器节点,以及 Client for Library、Client for Dorm、Client for Main Building 三个客户端节点及其连接。

第40页:用版类扩展UML

Extending the UML(扩展 UML):

  • Stereotypes can be used to extend the UML notational elements(版类可用于扩展 UML 的表示元素)
  • 版类可用于分类和扩展关联、继承关系、类和构件
  • 示例:类版类 boundary、control、entity、utility、exception;继承版类 uses 和 extends;构件版类 subsystem

第41页:迭代生命周期不是什么

7.3 迭代式开发过程 —— What the Iterative LifeCycle Is Not(迭代生命周期不是什么):

  • It is not hacking(不是蛮干)
  • It is not a playpen for developers(不是开发人员的游乐场)
  • It is not unpredictable(不是不可预测的)
  • It is not redesigning the same thing over and over until it is perfect(不是反复重做同一件事直到完美)
  • It is not an excuse for not planning and managing a project(不是不做计划与项目管理的借口)
  • It is not something that affects only the developers on a project(不只是影响开发人员)

第42页:迭代生命周期是什么

What the Iterative LifeCycle Is(迭代生命周期是什么):

  • It is planned and managed(有计划并被管理)
  • It is predictable(可预测)
  • It accommodates changes to requirements with less disruption(以较小的扰动适应需求变更)
  • It is based on evolving executable prototypes, not documentation(基于不断演进的可执行原型,而非文档)
  • It involves the user/customer throughout the process(用户/客户全程参与)
  • It is risk driven(风险驱动)

第43页:迭代方法的三个重要特征

Three Important Features of the Iterative Approach(迭代方法的三个重要特征):

  • Continuous integration(持续集成)——不是临近交付时一次性集成
  • Frequent, executable releases(频繁的可执行发布)——部分内部发布,部分对外交付
  • Attack risks through demonstrable progress(通过可验证的进展化解风险)——进展以产品衡量,而非文档或工程估算

第44页:迭代带来的收益

Resulting Benefits(迭代带来的收益):

  • Releases are a forcing function that drives the development team to closure at regular intervals(发布是推动团队按固定节奏收口的强制机制)
  • Can incorporate problems/issues/changes into future iterations rather than disrupting ongoing production(问题与变更可在后续迭代中吸收,而不打断正在进行的生产)
  • 项目的支撑角色(测试人员、文档人员、QA 等)可以更好地安排自己的工作

第45页:迭代开发的风险剖面

Risk Profile of an Iterative Development(迭代开发的风险剖面):对比 Waterfall(瀑布)与迭代方式的时间—风险曲线。迭代过程分为 Inception、Elaboration、Construction、Transition 与 Post-deployment 各阶段,含 Preliminary Iteration、Architectural Iteration、Development Iteration、Transition Iteration 等,风险随迭代推进持续下降。

第46页:分阶段的风险管理

Risk Management Phase-by-Phase(分阶段的风险管理):

  • Inception(初始):通过构建概念验证(proof of concept)框定项目风险
  • Elaboration(精化):通过与最终用户和领域专家探讨场景,形成对系统范围与期望行为的共识;建立系统架构;设计处理全局性问题的公共机制

第47页:分阶段的风险管理(续)

Risk Management Phase-by-Phase (cont.)(分阶段的风险管理续):

  • Construction(构造):精化架构、风险驱动的迭代、持续集成
  • Transition(交付):促进用户验收、度量用户满意度
  • Post-deployment cycles(部署后周期):继续演进式方法、保持架构完整性

第48页:风险降低驱动迭代

Risk Reduction Drives Iterations(风险降低驱动迭代):初始项目风险与初始项目范围出发,经过 Plan Iteration N(成本、进度)、Develop Iteration N(定义针对最高风险的场景、收集成本与质量度量)、Assess Iteration N,消除部分风险后修订项目风险并重新排序,再修订总体项目计划(成本、进度、范围/内容),形成闭环。

第49页:用例驱动迭代过程

Use Cases Drive the Iteration Process(用例驱动迭代过程):在 Inception、Elaboration、Construction、Transition 四个阶段中依次安排 Iteration 1、Iteration 2、Iteration 3,每个迭代内部按 Rqmts Capture、Analysis & Design、Implementation、Test、Prepare Release 组织为迷你瀑布(mini-Waterfall)过程,并由 Iteration Planning 启动。

第50页:迭代生命周期:迷你瀑布

The Iteration Life Cycle: A Mini-Waterfall(迭代生命周期:迷你瀑布):

  • 输入:Results of previous iterations(前一迭代的结果)、Up-to-date risk assessment(最新风险评估)、Controlled libraries of models, code, and tests(受控的模型、代码与测试库)、Selected scenarios(选定的场景)
  • 活动:Iteration Planning、Requirements Capture、Analysis & Design、Implementation、Test、Prepare Release
  • 输出:Release description(发布说明)、Updated risk assessment(更新的风险评估)、Controlled libraries(受控库)

第51页:迭代计划活动

Detailed Iteration LifeCycle Activities —— Iteration planning(迭代计划):

  • 迭代开始前应基于前一迭代的结果(若有)与项目最新风险评估确定本次迭代的总体目标
  • 确定本次迭代的评价准则
  • 编制详细的迭代计划并纳入开发计划:包含用于监控进展的中间里程碑,包含走查与评审

第52页:需求捕获活动

Detailed Iteration LifeCycle Activities (cont.) —— Requirements Capture(需求捕获):

  • 选择/定义本次迭代要实现的用例
  • 更新对象模型以反映新发现的领域类与关联
  • 编制本次迭代的测试计划

第53页:分析设计与实现活动

Analysis & Design 与 Implementation(分析与设计、实现):

  • 分析与设计:确定本次迭代要开发或更新的类;更新对象模型以反映新发现的设计类与关联;必要时更新架构文档;开始编写测试规程
  • 实现:由设计模型自动生成代码;手工编写操作代码;完成测试规程;进行单元测试与集成测试

第54页:测试与发布准备活动

Test 与 Prepare the release description(测试与发布准备):

  • 测试:将本次开发的代码与系统其余部分(先前发布)集成并测试;捕获并评审测试结果;对照评价准则评估测试结果;进行迭代评估
  • 准备发布说明:同步代码与设计模型;将本次迭代的产品放入受控库

第55页:迭代内的工作分配

Work Allocation Within an Iteration(迭代内的工作分配):

  • 迭代内要完成的工作由(新的)待实现用例与需要返工的部分决定
  • 包是方便开发人员使用的工作包:高层包可分配给团队,低层包可分配给个人
  • 用例是方便测试与评估团队使用的工作包
  • 包还可用于确定配置管理的粒度,例如以单个包为单位签入签出

第56页:迭代评估

Iteration Assessment(迭代评估):

  • 对照迭代计划阶段确立的评价准则评估迭代结果:Functionality(功能)、Performance(性能)、Capacity(容量)、Quality measures(质量度量)
  • 考虑本次迭代期间发生的外部变化,例如需求、用户需要、竞争对手计划的变化
  • 确定需要哪些返工,并将其分配到剩余的迭代中

第57页:迭代次数与长度的选择

Selecting Iterations(选择迭代):

  • How many iterations do I need?(需要多少次迭代)在 18 个月以内的项目中,通常 3 到 6 次迭代
  • 所有迭代的长度是否相同?通常相同;迭代长度可按阶段变化,例如精化阶段的迭代可能比构造阶段的迭代更短

第58页:第一次迭代

The First Iteration(第一次迭代):

  • 第一次迭代通常是最困难的:需要整个开发环境和大部分开发团队到位,许多工具集成、团队建设、人员配备问题必须解决
  • 初次采用迭代方式的团队往往过于乐观
  • 对第一次迭代可完成的功能量应保守估计,否则首次迭代将延期、迭代总数减少、迭代方法的收益降低

第59页:没有银弹

There Is No Silver Bullet(没有银弹):

  • 采用迭代生命周期的主要原因:你不可能一开始掌握全部信息,开发期间事物会发生变化
  • 必须预期到:部分风险不会按计划消除;中途会发现新的风险;需要一些返工,某些为迭代编写的代码会被丢弃;需求会沿途变化

第60页:本章小结

Summary(本章小结):Analysis and Design Process with UML(使用 UML 的分析与设计过程):

  • 1. Identify actors and use cases(识别执行者与用例)
  • 2. Realize use cases with sequence and/or collaboration diagrams(用顺序图和/或合作图实现用例)
  • 3. Describe classes and their relationships in the logical view(在逻辑视图中描述类及其关系)
  • 4. Create state diagrams for objects(为对象创建状态图)
  • 5. Illustrate the organizations and dependencies among software components with component diagrams(用构件图说明软件构件的组织与依赖)
  • 6. Visualize configuration and distribution with deployment diagrams(用配置图可视化配置与分布)
顶部目录