第二章 UML简介

目录

m 1.概念模型
  构成要素
  规则
  公共机制
m 2.体系结构
m 3.Hello,UML!

2.1 UML概念模型

m UML建模的三要素
  UML构成要素(Building Blocks)
  规则(Rules)
  公共机制 (Common Mechanisams)
 
  协同工作建立起各种模型图,形成了该语言的概念模型

2.1.1 UML构成要素

m 基本元素(Things)
m 关系 (Relationships)
m 模型图 (Diagrams)

基本元素是对模型中首要成分的抽象

关系把基本元素结合在一起

模型图聚集了相关的基本元素

Building Block-构成要素(构造块)


基本元素

m 结构元素(Structural thing)
  1.类(class)
 
 
 
  2.接口(interface)
 

UML模型中的名词

模型的静态部分,描述概念元素或物理元素。

称为类目(classifier)


  3. 协作(collaboration)
 
 
  4. 用例(use case)
 
 
  5. 主动类(active class)
 
 

协作定义了一个交互,由一组共同工作以提供某种协作行为的角色和其他元素构成的一个群体。

一个给定的类或对象可以参与几个协作。

用例是对一组动作序列的描述,系统执行这些动作将产生对参与者有价值而且可观察的结果。

主动类的对象至少拥有一个进程或线程,因此它能够启动控制活动。



  6. 构件(component)
 
 
  7. 制品 (artifacts)
 
 
  8. 结点 (node)

构件是系统设计的模块化部件。

制品是系统中物理的而且可替换的部件。

结点是运行时存在的物理元素。表示一个计算机资源。

前6种表示概念或逻辑元素,后2种表示物理元素。


m 行为元素
  1. 交互(interaction)
 
  2. 状态机(state machine)
 
 
  3. 活动(activity)

行为元素是UML模型的动态部分。是模型中的动词,代表了跨越时间和空间的行为。

交互由在特定语境中共同完成一定任务的一组对象或角色之间交换的消息组成。

状态机描述了一个对象或一个交互在生命期内响应事件所经历的状态序列及它对这些事件作出的响应。

活动描述了计算过程执行的步骤序列。


m 分组元素(grouping thing)

m 注释元素(annotational thing)


分组元素是UML模型的组织部分。

注释元素是UML模型的解释部分。


 关系
m 1. 依赖 (dependency)

m 2. 关联 (association)

m 3. 泛化 (generalization)

m 4. 实现 (realization)


依赖:其中一个元素(独立元素)发生变化会影响另一个元素(依赖元素)的语义。

关联:类之间的结构关系,描述一组链,链是对象之间的连接。聚合是特殊类型的关联。

泛化:特殊和一般的关系。特殊元素(子元素)基于一般元素(父元素)而建立。

实现:类目之间的语义关系,其中一个类目指定了另一个类目保证执行的合约。

模型图(Diagrams)
m 1. 类图(class diagram)
m 2. 对象图(object diagram)
m 3. 构件图(component diagram)
m 4. 组合结构图(composite structure diagram)
m 5. 用例图(use case diagram)
m 6. 顺序图(sequence diagram)
m 7. 通信图(communication diagram)
m 8. 状态图(state diagram)
m 9. 活动图(activity diagram)
m 10.部署图(deployment diagram)
m 11.包图(package diagram)
m 12.定时图(timing diagram)
m 13.交互概览图(interaction overview diagram)

m A class diagram shows a set of classes, interfaces, and collaborationsand their relationships. These diagrams are the most common diagram found inmodeling object-oriented systems. Class diagrams address the static design viewof a system.

m An object diagram shows a set of objects and their relationships.Object diagrams represent static snapshots of instances of the things found inclass diagrams. These diagrams address the static design view or static processview of a system as do class diagrams, but from the perspective of real orprototypical cases.

m A component diagram is shows an encapsulated class and its interfaces,ports, and internal structure consisting of nested components and connectors.Component diagrams address the static design implementation view of a system.They are important for building large systems from smaller parts.

m A use case diagram shows a set of use cases and actors (a special kindof class) and their relationships. Use case diagrams address the static usecase view of a system. These diagrams are especially important in organizingand modeling the behaviors of a system.

m Both sequence diagrams and communication diagrams are kinds ofinteraction diagrams. An interaction diagram shows an interaction, consistingof a set of objects or roles, including the messages that may be dispatchedamong them. Interaction diagrams address the dynamic view of a system. Asequence diagram is an interaction diagram that emphasizes the time-ordering ofmessages; a communication diagram is an interaction diagram that emphasizes thestructural organization of the objects or roles that send and receive messages.

m A state diagram shows a state machine, consisting of states,transitions, events, and activities. A state diagrams shows the dynamic view ofan object. They are especially important in modeling the behavior of aninterface, class, or collaboration and emphasize the event-ordered behavior ofan object, which is especially useful in modeling reactive systems

m An activity diagram shows the structure of a process or othercomputation as the flow of control and data from step to step within thecomputation. Activity diagrams address the dynamic view of a system. They areespecially important in modeling the function of a system and emphasize theflow of control among objects.

m A deployment diagram shows the configuration of run-time processingnodes and the components that live on them. Deployment diagrams address thestatic deployment view of an architecture. A node typically hosts one or moreartifacts.

m A package diagram shows the decomposition of the model itself intoorganization units and their dependencies.
m A timing diagram is an interaction diagram that shows actual timesacross different objects or roles, as opposed to just relative sequences ofmessages.
m An interaction overview diagram is a hybrid of an activity diagram anda sequence diagram.


2.1.2 UML规则

m 语法规则和语义规则
m 用于:

     命名

     范围

     可见性

     完整性

     执行

m 不能简单地把UML构成要素按随机的方式堆放在一起。
m 形式良好的模型应该在语义上前后一致,并且与所有的相关模型协调一致。

2.1.3 UML公共机制

m 1. 规约(specifications)
     提供对构成要素的语法和语义的文字叙述。
     图形表示法用来对系统进行可视化,规约用来说明系统的细节。
m 2. 修饰(adornments)
     每个元素都有一个基本符号,
  可以把修饰细节加到这个符号上。

m 3.通用划分(common divisions)
  (1)类和对象的划分


  (2)接口和实现的分离
 
  (3)类型和角色的分离
 
m 4. 扩展机制(extensibility mechanism)
  (1)构造型(stereotypes)
  (2)标记值(tagged value)
  (3)约束(constraints)

2.2 UML体系结构

m 体系结构是一组重要决策:
  软件系统的组织
  对组成系统的结构元素及其接口的选择
  元素间的协作中描述的行为
  把结构和行为元素组合成逐步增大的子系统
  指导这种组织的结构风格

m 用例视图
  描述形成系统体系结构的动力。
 
  使用者:最终用户、分析人员、测试人员
m 设计视图(design view)
 
  系统提供给最终用户的服务。
  包含类、接口、协作,形成问题及其解决方案的词汇。
 
  使用者:设计人员和开发人员
m 交互视图(interaction view)
 
  展示系统不同部分之间的控制流,包括可能的并发和同步机制。
  主要针对性能、可伸缩性和系统的吞吐量。
 
  使用者:开发者。
m 实现视图(implementation view)
 
  针对系统发布的配置管理。
  包含了用于装配与发布物理系统的制品。
 
  使用者:开发者。
m 部署视图(deployment view)
 
  主要描述组成物理系统的部件的分布、交付和安装。
  包含了形成系统硬件拓扑结构的结点。
 
  使用者:开发人员、系统集成人员、测试人员。
 
     五种视图每一种都可单独使用,使不同的人员能专注于他们最为关心的体系结构的问题。
 
     五种视图也会相互作用。

UML视图和模型图

UML中的各种概念和构造并无严格的界限,为了方便,将其分成几种视图。

视图试代表系统某个方面的建模结构的子集。

模型图试模型元素集合的图形化表示,用狐(关系)连接顶点(模型元素)描述。

ProfileThedefinition of a set of limited additions to a base metamodelto adapt it to a specific platform or domain.

简档:将基本元模型应用于一个特定平台或领域时,对一组有限的附加说明的定义。

2.3  Hello,UML!

m 1.关键抽象
  应用需求:在web浏览器显示“Hello,World!”。
  java代码如下:
 
import java.awt.Graphics;
 class HelloWorld extendsjava.applet.Applet{
   public void paint(Graphics g){
      g.drawString("Hello,World!",10,10);
   }
 }

此类图只反映了Hello应用的基本部分


进一步描述应用类与其他类关系

直接相关类

继承树

用包图显示组织管理关系

m 2.机制


动态建模

描述系统的行为,

用顺序图展示关键对象的协作,

从而揭示系统的运行机制,加深对需求的理解

m 3.制品

物理视图建模

applet不能单独存在运行,只是应用系统的一部分——制品

制品是一种物理表示,如文件。源代码和二进制程序都表现了(物理上实现了)逻辑类

图符是带有《artifact》构造型的矩形,也可用自定义图标

小结

m UML是一种对软件系统的制品进行详述、可视化、构建、文档化的语言。
m UML的概念模型:构成要素、规则、公共机制
m 构成要素包括:基本要素(4)、关系(4)、模型图(13)
m “4+1”体系结构



















  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值