SEMANTICS OF UML

合集下载

UML类图关系泛化、继承、实现、依赖、关联、聚合、组合

UML类图关系泛化、继承、实现、依赖、关联、聚合、组合

继承、实现、依赖、关联、聚合、组合的联系与区别分别介绍这几种关系:继承实现指的是一个class 类实现interface 接口(可以是多个)的功能;实现是类与接口之间最常 见的关系;在Java 中此类关系通过关键字implements 明确标识,在设计时一般没有争 议性;依赖可以简单的理解,就是一个类A 使用到了另一个类B ,而这种使用关系是具有偶然性的、、 临时性的、非常弱的,但是B 类的变化会影响到A ;比如某人要过河,需要借用一条船, 此时人与船之间的关系就是依赖;表现在代码层面,为类B 作为参数被类A 在某个method 方法中使用;Inte rfare指的是一个类(称为子类、子接口)继承另外的一个类(称为父类、父接口)的功能,并可 以增加它自己的新功能的能力,继承是类与类或者接口与接口之间最常见的关系;在Java 中此类关系通过关键字extends 明确标识,在设计时一般没有争议性;b lnterface_BQlass_A ClaSs_B关联他体现的是两个类、或者类与接口之间语义级别的一种强依赖关系,比如我和我的朋友;这 种关系比依赖更强、不存在依赖关系的偶然性、关系也不是临时性的,一般是长期性的,而 且双方的关系一般是平等的、关联可以是单向、双向的;表现在代码层面,为被关联类B 以类属性的形式出现在关联类A 中,也可能是关联类A 引用了一个类型为被关联类B 的全 局变量;聚合聚合是关联关系的一种特例,他体现的是整体与部分、拥有的关系,即has-a 的关系,此 时整体与部分之间是可分离的,他们可以具有各自的生命周期,部分可以属于多个整体对象, 也可以为多个整体对象共享;比如计算机与CPU 、公司与员工的关系等;表现在代码层面, 和关联关系是一致的,只能从语义级别来区分;组合组合也是关联关系的一种特例,他体现的是一种contains-a 的关系,这种关系比聚合更强, 也称为强聚合;他同样体现整体与部分间的关系,但此时整体与部分是不可分的,整体的生 命周期结束也就意味着部分的生命周期结束;比如你和你的大脑;表现在代码层面,和关联 关系是一致的,只能从语义级别来区分;对于继承、实现这两种关系没多少疑问,他们体现的是一种类与类、或者类与接口间的纵向 关系;其他的四者关系则体现的是类与类、或者类与接口间的引用、横向关系,是比较难区 分的,有很多事物间的关系要想准备定位是很难的,前面也提到,这几种关系都是语义级别Cl3ss A 十 depend<Qlass.B classBJ ;:;;VoidClass_B的,所以从代码层面并不能完全区分各种关系;但总的来说,后几种关系所表现的强弱程度依次为:组合>聚合>关联》依赖;聚合跟组合其实都属于关联只不过它们是两种特殊的关联因为本是同根生所以它们之间难 免会有相似之处下面让我们一起来看一下它们之间有何不同聚合与组合的概念相信不用我在此赘述大家就已经了解了下面直接上例子 程老师的《大话》里举大那个大雁的例子很贴切在此我就借用一下大雁喜欢热闹害怕孤独所 以它们一直过着群居的生活这样就有了雁群每一只大雁都有自己的雁群每个雁群都有好多 大雁大雁与雁群的这种关系就可以称之为聚合另外每只大雁都有两只翅膀大雁与雁翅的关 系就叫做组合有此可见聚合的关系明显没有组合紧密大雁不会因为它们的群主将雁群解散 而无法生存而雁翅就无法脱离大雁而单独生存一一组合关系的类具有相同的生命周期聚合关系图:构造函数不同雁群类:[csharp] view plaincopypublic class GooseGroup { public Goose goose; public GooseGroup(Goose goose) { this .goose = goose;} 10. }[csharp] view plaincopy1. 2. 3.4.5. 6.7. 8.9. 组合关系图:从从代码上看这两种关系的区别在于:1.public class GooseGroup2.{3.public Goose goose;4.5.6.public GooseGroup(Goose goose)7.{8.this.goose = goose;9.}10.}大雁类:[csharp] view plaincopy1.public class Goose2.{3.public Wings wings;4.5.public Goose()6.{7.wings=new Wings();8.}9.}[csharp] view plaincopy1.public class Goose2.{3.public Wings wings;4.5.public Goose()6.{7.wings=new Wings();8.}9.}聚合关系的类里含有另一个类作为参数雁群类(GooseGroup)的构造函数中要用到大雁(Goose)作为参数把值传进来大雁类(Goose)可以脱离雁群类而独立存在组合关系的类里含有另一个类的实例化大雁类(Goose)在实例化之前一定要先实例化翅膀类(Wings)两个类紧密耦合在一起它们有相同的生命周期翅膀类(Wings)不可以脱离大雁类(Goose)而独立存在信息的封装性不同在聚合关系中,客户端可以同时了解雁群类和大雁类,因为他们都是独立的而在组合关系中,客户端只认识大雁类,根本就不知道翅膀类的存在,因为翅膀类被严密的封装在大雁类中。

UML图中类之间的关系_依赖,泛化,关联,聚合,组合,实现答辩

UML图中类之间的关系_依赖,泛化,关联,聚合,组合,实现答辩

UML图中类之间的关系:依赖,泛化,关联,聚合,组合,实现1.2.3.4.5.6.类与类图1 类(Class封装了数据和行为,是面向对象的重要组成部分,它是具有相同属性、操作、关系的对象集合的总称。

2 在系统中,每个类具有一定的职责,职责指的是类所担任的任务,即类要完成什么样的功能,要承担什么样的义务。

一个类可以有多种职责,设计得好的类一般只有一种职责,在定义类的时候,将类的职责分解成为类的属性和操作(即方法)。

3 类的属性即类的数据职责,类的操作即类的行为职责一、依赖关系(Dependence依赖关系(Dependence):假设A类的变化引起了B 类的变化,则说名B类依赖于A类。

• 依赖关系(Dependency 是一种使用关系,特定事物的改变有可能会影响到使用该事物的其他事物,在需要表示一个事物使用另一个事物时使用依赖关系。

大多数情况下,依赖关系体现在某个类的方法使用另一个类的对象作为参数。

• 在UML中,依赖关系用带箭头的虚线表示,由依赖的一方指向被依赖的一方。

[java] view plaincopyprint?1. public class Driver2. {3. public void drive(Car car4. {5. car.move(;6. }7. ……8. }9. public class Car10. {11. public void move(12. {13. ......14. }15. ……16. }{car.move(;}……}public class Car{public void move({......}……}依赖关系有如下三种情况:1、A类是B类中的(某中方法的)局部变量;2、A类是B类方法当中的一个参数;3、A类向B类发送消息,从而影响B类发生变化;GeneralizationGeneralization A是B和C的父类,B,C具有公共类(父类)A,说明A是B,C的一般化(概括,也称泛化)• 泛化关系(Generalization也就是继承关系,也称为“is-a-kind-of”关系,泛化关系用于描述父类与子类之间的关系,父类又称作基类或超类,子类又称作派生类。

UML的定义和组成详细介绍

UML的定义和组成详细介绍

UML的定义和组成详细介绍⽬录1、UML1.1概述UML(Unified Modeling Language 统⼀建模语⾔) 是为软件系统的制品进⾏描述(specifying)、可视化(visualizing)、构造(constructing)、⽂档化(documenting)的⼀种语⾔。

UML规范⽤来描述建模的概念有: 类、对象、关联、职责、⾏为、接⼝、⽤例、包、顺序、协作,以及状态。

1.2 UML是⼀种建模语⾔建模⽅法 = 建模语⾔ + 建模过程。

建模语⾔定义了⽤于表⽰设计的符号(通常是图形符号);建模过程描述进⾏设计所需要遵循的步骤。

标准建模语⾔UML是⼀种建模语⾔,⽽不是⼀种⽅法,它统⼀了⾯向对象建模的基本概念、术语及其图形符号,为⼈们建⽴了便于交流的共同语⾔。

建模能⼒:建模⽅法 + 领域知识 + 实践1.3 UML语⾔包含三⽅⾯1. UML基本图素:它是构成UML模型图的基本元素。

例如类、对象、包、接⼝、组件等。

2. UML模型图:它由UML基本图素按照UML建模规则构成。

例如⽤例图、类图、对象图、…等。

3. UML建模规则:UML模型图必须按特定的规则有机地组合⽽成,从⽽构成⼀个有机的、完整的UML模型图(well-formed UMLdiagram)。

2、UML⽀持软件体系结构建模为了表达不同的软件开发相关⼈员在软件开发周期的不同时期看待软件产品的不同侧重⾯, 需要对模型进⾏分层。

UML根据软件产品的体系结构(architecture)对软件进⾏分层。

软件的体系结构分解为五个不同的侧⾯,称为4+1视图(view)。

分别是:⽤例视图(Use case view,Scenarios)—场景视⾓逻辑视图(Logical view) — 逻辑视⾓进程(过程)视图(Process view) — 过程视⾓实现(开发)视图(Implementation view) —开发视⾓部署(物理、配置)视图(Deployment view) —物理视⾓每个视图分别关注软件开发的某⼀侧⾯视图由⼀种或多种模型图(diagram)构成模型图描述了构成相应视图的基本模型元素(element)及它们之间的相互关系。

UML九种视图总结

UML九种视图总结

UML九种视图总结第一篇:UML九种视图总结1.UML关系UML类图中的关系分为四种:泛化关系、依赖关系、关联关系、实现关系;关联关系又可以细化为聚合和组合。

1.1 泛化(Generalization)泛化是父类和子类之间的关系,子类继承父类的所有结构和行为。

在子类中可以增加新的结构和行为,也可以覆写父类的行为。

1.2.依赖(Dependencies)依赖关系是一种使用关系,特定事物的改变有可能会影响到使用该事物的事物,反之不成立。

在你想显示一个事物使用另一个事物时使用,两个元素之间的一种关系,其中一个元素(服务者)的变化将影响另一个元素(客户),或向它(客户)提供所需信息。

它是一种组成不同模型关系的简便方法。

依赖表示两个或多个模型元素之间语义上的关系。

它只将模型元素本身连接起来而不需要用一组实例来表达它的意思。

它表示了这样一种情形,提供者的某些变化会要求或指示依赖关系中客户的变化。

根据这个定义,关联和泛化都是依赖关系,但是它们有更特别的语义,故它们有自己的名字和详细的语义。

我们通常用依赖这个词来指其他的关系。

依赖用一个从客户指向提供者的虚箭头表示,用一个构造型的关键字来区分它的种类,通常情况下,依赖关系体现在某个类的方法使用另一个类作为参数。

1.3.关联(Association)关联是一种结构化的关系,指一种对象和另一种对象有联系。

给定有关联的两个类,可以从一个类的对象得到另一个类的对象。

类与类之间由弱到强关系是: 没关系 > 依赖 > 关联 > 聚合 > 组合。

类和类之间八竿子打不着那就是没关系,这个没啥歧义。

依赖(dependency)可以简单的理解,就是一个类A使用到了另一个类B,而这种使用关系是具有偶然性的、、临时性的、非常弱的,但是B类的变化会影响到A;比如某人要过河,需要借用一条船,此时人与船之间的关系就是依赖;表现在代码层面,为类B作为参数被类A在某个method 方法中使用。

uml相关的名词解释

uml相关的名词解释

uml相关的名词解释UML(统一建模语言)相关名词解释简介:在软件工程中,统一建模语言(UML)是一种标准化的、通用的建模语言,用于描述和构建软件系统。

被广泛应用于软件开发过程中的需求分析、系统设计、代码生成等环节,UML具备描述问题领域、定义软件结构和行为的能力,以及促进开发者之间的交流和沟通。

本文将对与UML相关的一些关键名词进行解释与阐述。

1. 用例图(Use Case Diagram)用例图是UML中最常用的图形之一,用于描述系统与用户之间的交互。

用例图通过显示系统的功能和角色之间的关系,来帮助开发者理解和定义系统的需求。

用例图中的参与者代表系统的用户、外部组织或其他系统,而用例则代表系统的功能或交互场景。

用例图可以帮助团队更好地理解系统的需求,从而指导系统的设计和开发过程。

2. 类图(Class Diagram)类图是用于描述系统中的类、接口、关系和结构的图形化工具。

在类图中,类被表示为矩形框,类之间的关系以及类的属性和方法则通过箭头连接来表示。

类图可以帮助开发者理解、设计和组织系统中的类与对象之间的结构关系,从而更好地进行系统设计和编码。

3. 时序图(Sequence Diagram)时序图用于描述对象之间的交互,尤其是强调交互的顺序和时序逻辑。

时序图中的对象以及它们之间的消息传递被表示为垂直的时间轴和消息顺序。

时序图可以帮助开发者理解和描述系统中对象之间的交互过程,以及时间上的先后关系。

4. 活动图(Activity Diagram)活动图用于描述系统中的行为和流程,强调系统中的活动和动作。

活动图以节点和边的形式描述活动的流程和顺序,用于展示系统中各个活动之间的流转和控制。

活动图可以帮助开发者分析和设计系统中的流程,以及理解系统的行为逻辑。

5. 组件图(Component Diagram)组件图用于描述系统的组件和它们之间的关系,关注系统的组织结构和组件之间的依赖关系。

在组件图中,组件被表示为矩形框,组件之间的关系以及组件的接口则使用箭头表示。

13种uml简介、工具及示例

13种uml简介、工具及示例

13种uml简介、工具及示例UML(Unified Modeling Language)是一种用于软件开发的标准化建模语言,它使用图形表示法来描述软件系统的不同方面。

在软件开发过程中,使用UML可以帮助开发人员更清晰地理解系统的结构和行为,从而更好地进行设计和实现。

UML提供了包括结构模型、行为模型和交互模型在内的多种建模方式,其中每种模型都有各自的符号和语法规则。

通过使用这些模型,开发人员可以将系统分解成不同的部分,然后逐步细化这些部分的设计,以便更好地组织和管理项目。

在UML中,最常用的建模元素包括用例图、类图、时序图、活动图、状态图等。

每种图表都有其特定的用途和表达能力,开发人员可以根据实际需要选择合适的图表进行建模。

除了建模元素外,UML还定义了一系列的建模工具,这些工具可以帮助开发人员更高效地进行建模和分析。

其中一些常用的建模工具包括Enterprise Architect、Rational Rose、StarUML等。

下面将对13种UML简介、工具及示例进行详细介绍:1. 用例图(Use Case Diagram)用例图是UML中描述系统功能和用户交互的基本图表之一。

它用椭圆表示用例,用直线连接用例和参与者,展示了系统外部用户和系统之间的交互。

用例图可以帮助开发人员更清晰地理解系统的功能需求,从而指导系统的设计和实现。

示例:一个简单的在线购物系统的用例图包括用例“浏览商品”、“添加商品到购物车”、“提交订单”等,以及参与者“顾客”和“管理员”。

2. 类图(Class Diagram)类图是UML中描述系统结构和静态关系的基本图表之一。

它用矩形表示类,用线连接类之间的关系,包括关联关系、聚合关系、继承关系等。

类图可以帮助开发人员更清晰地理解系统的对象结构和类之间的关系,从而支持系统的设计和重构。

示例:一个简单的学生信息管理系统的类图包括类“学生”、“课程”、“教师”等,以及它们之间的关系如“选修”、“授课”等。

UML的十种视图

UML的十种视图

三、UML的十种视图1.用例图(use case diagram)从系统的外部用户的观点看系统应具有的功能。

它只说明系统实现什么功能,而不必说明如何实现。

用例图主要用于对系统,子系统或类的行为进行建模。

2.类图(class diagram)描述系统的静态结构,类图的节点表示系统中的类及其属性和操作,边表示类之间的联系(包括继承(泛化)、关联、聚集)。

3.对象图(object diagram)类图的一种变形,所使用的符号与类图基本相同。

在对象名下面要加下划线。

(图略)4.包图(packet diagram)包是基于模型元素的含义或作用将模型元素分组的一种机制。

通过分组,可提高模型的维持性。

包之间的关系包括继承、构成与依赖。

5.顺序(时序)图(sequence diagram)交互图之一。

描述了在时间上对象交互的安排,展现了多个交互对象以及信息交流的序列。

时序图包含对象、对象的生命线、按顺序对象间的信息交流、控制焦点(可选的)。

6.合作(协作)图(collaboration diagram)交互图之二,强调发送和接收消息的对象间的结构组织,它与顺序图是等价的。

在图形上,协作图是顶点和弧的结合。

协作图包含对象、链、消息。

(图片来自《软件工程(第二版)》齐治昌、谭庆平、宁洪)7.状态图(statechart diagram)状态图描述类的对象的动态行为。

它包含对象所有可能的状态、活动图描述系统为完成某项功能而执行的操作序列,这些在每个状态下能够响应的事件以及事件发生时的状态迁移与响应动作。

操作序列可以并发和同步。

8.活动图(activity diagram)活动图中包含控制流和信息流。

控制流表示一个操作完成后对其后续操作的触发,信息流则刻画操作之间的信息交换。

提供了对工作流进行建模的途径,活动图中的活动,表示执行工作流中一组的动作。

一旦结束,控制流将自动转移到下一个活动,或通过转换进入下一个状态。

9.构件图(component diagram)提供当前模型的物理视图,对系统的静态实现视图进行建模。

semantic名词

semantic名词

semantic名词
1. 语义学(Semantics):研究语言意义的学科,包括词汇、句法和语境等方面。

2. 语义(Semantics):指语言中词汇、短语、句子和篇章的意义。

3. 语义角色(Semantic Roles):指在句子中扮演不同语义角色的成分,如主语、宾语、谓语等。

4. 语义网络(Semantic Network):指将语言中的概念和它们之间的关系用图形方式表示出来的一种方法。

5. 语义分析(Semantic Analysis):指对自然语言文本进行分析,以确定其意义和语义结构。

6. 语义模型(Semantic Model):指用来表示语言中词汇、短语、句子和篇章的意义的一种模型。

7. 语义推理(Semantic Inference):指根据已知的语义信息,推断出新的语义信息的过程。

8. 语义消歧(Semantic Disambiguation):指在自然语言处理中,确定一个词或短语在特定上下文中的确切含义的过程。

9. 语义相似度(Semantic Similarity):指在语义空间中,两个词或
短语之间的相似程度。

10. 语义标注(Semantic Annotation):指将自然语言文本中的词汇、短语、句子和篇章进行语义标记的过程。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Meta-Modelling Semantics of UML1Chapter1KEYWORDS,ETC.(The first two pages only resemble the abtract infos and areneeded to ensure proper layout of the rest of the article.Bernhard)--------Name(s)and affiliation(s):Andy EvansUniversity of York,York,UKandye@Robert FranceColorado State University,Colorado,USfrance@Kevin LanoImperial College,London,UKkcl@Bernhard RumpeSoftware\&Systems EngineeringMunich University of Technology,Munich,Germanyrumpe@in.tum.deTitle:Meta-Modelling Semantics of UMLIndex items:UML,Meta-model,Theory,Formalization,OCL,Semantics,GeneralisationAbstract:---------The Unified Modelling Language is emerging as a de-facto standard for modelling object-oriented systems.However,the semantics document that a part of the standard definition primarily provides a descriptionof the language’s syntax and well-formedness rules.The meaning of the language,which is mainly described in English,is too informal2Chapter4and unstructured to provide a foundation for developing formalanalysis and development techniques.This paper outlines a formalisation strategy for making precise the core semantics of UML.This is acheived by strengthening the denotational semantics of the existing UML semantics.To illustrate the approach,the semantics ofgeneralization/specializationare made precise.Chapter4 MET A-MODELLING SEMANTICS OF UMLAndy Evans University of York,UKandye@Robert France Colorado State University,US france@Kevin LanoImperial College,UKkcl@ Bernhard Rumpe Munich University of TechnologyGermanyrumpe@in.tum.deAbstract The Unified Modelling Language is emerging as a de-facto standard for mod-elling object-oriented systems.However,the semantics document that a part ofthe standard definition primarily provides a description of the language’s syntaxand well-formedness rules.The meaning of the language,which is mainly de-scribed in English,is too informal and unstructured to provide a foundation fordeveloping formal analysis and development techniques.This paper outlines aformalisation strategy for making precise the core semantics of UML.This isachieved by strengthening the denotational semantics of the existing UML meta-model.To illustrate the approach,the semantics of generalization/specializationare made precise.1.INTRODUCTIONThe Unified Modeling Language(UML)[BRJ98,RJB99]is rapidly becoming a de-facto language for modelling object-oriented systems.An important aspect of the language is the recognition by its authors of the need to provide a precise description of its semantics.Their intention is that this should act as an unambiguous description of the language,whilst also permitting extensibility so that it may adapt to future changes in object-oriented analysis and design.This has resulted in a Semantics Document [OMG99],which is presently being managed by the Object Management Group,and forms an important part of the language’s standard definition.46Chapter4 The UML semantics is described using a meta-model that is presented in terms of three views:the abstract syntax,well-formedness rules,and modelling element semantics.The abstract syntax is expressed using a subset of UML static modelling notations.The abstract syntax model is supported by natural language descriptions of the syntactic structure of UML constructs.The well-formedness rules are expressed in the Object Constraint Language(OCL)and the semantics of modelling elements are described in natural language.The advantage of using the meta-modelling approach is that it is accessible to anybody who understands UML.Furthermore,the use of object-oriented modelling techniques helps make the model more intuitively understandable.A potential advantage of providing a precise semantics for UML is that many of the benefits of using a formal language such as Z[S92]or Spectrum[BFG93]might be transferable to UML.Some of the major benefits of having a precise semantics for UML are given below:Clarity:The formally stated semantics can act as a point of reference to resolve disagreements over intended interpretation and to clear up confusion over the precise meaning of a construct.Equivalence and Consistency:A precise semantics provides an unambiguous basis from which to compare and contrast the UML with other techniques and notations,and for ensuring consistency between its different components.Extendibility:The soundness of extensions to the UML can be verified(as encouraged by the UML authors).Refinement:The correctness of design steps in the UML can be verified and precisely documented.In particular,a properly developed semantics supports the development of design transformations,in which a more abstract model is diagrammatically transformed into an implementation model.Proof:Justified proofs and rigorous analysis of important properties of a sys-tem described in UML require a precise semantics in order to determine their correctness.Unfortunately,the current UML semantics are not sufficiently formal to realise these benefits.Although much of the syntax of the language has been defined,and some static semantics given,its semantics are mostly described using lengthy paragraphs of often ambiguous informal English,or are missing entirely.Furthermore,limited consideration has been paid to important issues such as proof,compositionality and rigorous development.A further problem is the extensive scope of the language,all of which must be dealt with before the language is completely defined.This chapter describes work being carried out by the precise UML(pUML)group and documented in[PUML99,FELR98,EFLR98].PUML is an international group of researchers and practitioners who share the goal of developing UML as a precise (formal)modelling language,thereby enabling it to be used in a formal manner.This chapter reports on work being carried out by the group to strengthen the existing semantics of UML.In Section2.,a formalisation strategy is described(developed through the experiences of the group)that aims to make precise the existing UMLMeta-Modelling Semantics of UML47 semantics.A core UML semantics model is identified in Section3.as afirst step towards achieving this goal.Section4.then describes how the formalisation strategy has been applied to the development of a precise understanding of a small yet interesting part of the UML semantics-generalization/specialization hierarchies.Finally,the paper concludes with a brief overview of some future directions of the group’s work.2.FORMALISATION STRATEGYIn order to implement the pUML approach it is necessary to develop a strategy for formalising the UML.This is intended to act as a step by step guide to the formalisation process,thus permitting a more rigorous and traceable work program.In developing a formalisation strategy for UML it has been necessary to consider the following questions:1.Is the meta-modelling approach used in the current UML semantics suitable forassigning a precise semantics to UML?2.Should the existing UML semantics be used as a foundation for developing aprecise semantics for UML?3.Given the large scope of UML,which parts should be formalisedfirst?Suitability of meta-modellingThere are many approaches used to assign semantics to languages.One of the best known(and most popular)is the denotational approach(for an in-depth discussion see[S86]).The denotational approach assigns semantics to a language by giving a mapping from its syntactical representation to a meaning,called a denotation.A denotation is usually a well-defined mathematical value,such as a number or a set. Typically,functions are used to define mappings between syntax and denotations.For example,the meaning of a simple language for adding and subtracting natural numbers might be described in terms of two functions,add and subtract,and the result of each would be a single integer value.The use of a language to give a‘meta-circular’description of its own denotational semantics is well known in Computer Science.For example,the specification lan-guage Z has been given a meta-circular semantics using a simple subset of Z[S92]. Unfortunately,the meta-modelling approach opens itself to the criticism that it doesn’t really define rmally,if a reader does not understand UML,then it is unlikely that they will understand the meaning of UML when written in UML.The justification given for using meta-modelling in these contexts is that,in principle at least,it should be possible to give a formal interpretation to a meta-description in terms of a more basic language such as predicate logic.This argument can also be applied to UML,as it seems likely that it can be given a more fundamental interpretation in terms of sets and predicate logic.Indeed,a significant amount of work has already been done to describe the semantics of UML class diagrams and OCL like expressions [BR98]in Z.There is also an important pragmatic reason for choosing UML to describe the denotational semantics of UML:Because UML is designed to provide an intuitive48Chapter4 means for constructing models,using UML to help better understand UML is likely to be a useful way of testing the expressiveness and power of UML as a modelling language.Given that UML can be used to describe its own semantics,how should these semantics be presented in order to emphasise the denotational approach?As described in the introduction,the current UML semantics already makes a distinction between syntax and semantics(as in the denotational approach).However,it mainly uses English prose to describe the semantic part.The pUML approach advances this work by using associations(and constraints on associations)to map syntactical elements to their denotations.This approach has also been used in the UML semantics to a limited extent.For example,associations are described by the set of possible object links they are associated with.The distinguishing feature of the pUML approach is its emphasis on obtaining precise denotational descriptions of a much wider selection of UML modelling elements.Working with the standardAssuming that a meta-modelling approach is adopted to describe the UML se-mantics,two approaches to developing a precise semantics can be adopted.Thefirst approach is to ignore the existing semantics documentation and develop a new model. This has the advantage that the modeller is completely free to develop a semantics that is appropriate to their needs.For example,greater emphasis might be placed on obtaining a simple semantic model,or one that will readily support a particular proof technique.The second approach is to adopt the existing semantics as a foundation from which a precise semantics can be obtained.Some good reasons for adopting this approach are as follows:1.It recognises that considerable time and effort has been invested in the devel-opment of the existing UML semantics.It cannot be expected that a radically different semantic proposal will be incorporated in new versions.2.Without working within the constraints of the existing semantics it is easy todevelop models that are incompatible with the standard or omit important aspects of it.An important aspect of the pUML approach is its aim of eventually contributing to the emerging standard.Therefore,it is the second approach that has been adopted. This is why the remainder of the paper will focus on developing an approach to incrementally clarifying the existing semantics of UML.Clarifying a core semanticsTo cope with the large scope of the UML it is natural to concentrate on essential concepts of the language to build a clear and precise foundation as a basis for formalisa-tion.Therefore,the approach taken in the group’s work is to concentrate on identifying and formalising a core semantic model for UML before tackling other features of theMeta-Modelling Semantics of UML49 language.This has a number of advantages:firstly,it makes the formalisation task more manageable;secondly,a more precise core will act as a foundation for under-standing the semantics of the remainder of the language.This is useful in the case of the many diagrammatical notations supported by UML,as each diagram’s semantics can be defined as a particular‘view’of the core model semantics.For example,the meaning of an interaction diagram should be understandable in terms of a subset of the behavioural semantics of the core.Formalisation strategyThe formalisation strategy consists of the following steps:1.Identify the core elements of the existing UML semantics.2.Iteratively examine the core elements,seeking to verify their completeness.Here,completeness is achieved when:(1)the modelling element has a precise syntax,(2)is well-formed,and(3)has a precise denotation in terms of some fundamental aspect of the core semantic model.e formal techniques to gain better insight into the existing definitions as shownin[FELR98,EFLR98].4.Where in-completeness is identified,we attempt to address it in a number ofways,depending on the type of omission found.Model strengthening-this is necessary where the meaning of a modelelement is not fully described in the meta-model.The omission isfixed bystrengthening the relationship between the model element and its denota-tion.Model extension-in certain cases it is necessary to extend the meta-model to incorporate new denotational relationships.This occurs when nomeaning has been assigned to a particular model element,and it cannotbe derived by constraints on existing associations.For example,this isnecessary in the case of Operation and Method,where the meaning ofa method is defined in terms of a procedureExpression and Operation isgiven no abstract meaning at all.Model simplification-in some cases,aspects of the model are surplus toneeds,in which case we aim to show how they can be omitted or simplifiedwithout compromising the existing semantics.5.Feed the results back into the UML meta-model,with the aim of clarifying thesemantics of a core part of the UML.6.Disseminate to interested parties for feedback.Finally,it is important to consider how the notion of proof can be represented in the semantic model.This is essential if techniques are to be developed for analysing properties of UML models.Such analysis is required to establish the presence of50Chapter4 desired properties in models[E98].The need to establish properties can arise out of the need to establish that models adhere to requirements or out of challenges posed by reviewers of the models.Proof is also important in understanding properties of model transformations in which a system is progressively refined to an implementation [BHH97].3.THE CORE SEMANTICS MODELThe question of what should form a core precise semantics for UML is already par-tially answered in the UML semantics document.It identifies a‘Core Package-Relationships’package and a number of‘Common Behaviour’packages.The Core Relationship package defines a set of modelling elements that are common to all UML diagrams,such as ModelElement,Relationship,Classifier,Association and General-ization.However,it only describes their syntax.The Common Behavior(Instances and Links)package gives a partial denotational meaning to the model elements in the core package.For instance,it describes an association between Classifier and Instance.This establishes the connection between the representation of a Classifier and its meaning,which is a collection of instances.The meaning of Association(a collection of Object Links)is also given,along with a connection between Association roles and Attribute values.To illustrate the scope,and to show the potential for realising a compact core semantics,the relevant class diagrams of the two models are shown in the Figures4.1 and4.2.Well-formedness rules are omitted for brevity.An appropriate starting point for a formalisation is to consider these two models in isolation,with the aim of improving the rigor with which the syntax of UML model elements are associated with(or mapped to)their denotations.4.FILLING THE SEMANTIC GAPIn this section,we illustrate how the pUML formalisation approach has been applied to a small part of the core model.The modelling concept that will be investigated is generalization/specialization.4.1DESCRIPTIONIn UML,a generalization is defined as“a taxonomic relationship between a more general element and a more specific element”,where“the more specific element is fully consistent with the more general element”[OMG99],page2-34(it has all of its properties,members,and relationships)and may contain additional information.Closely related to the UML meaning of generalization is the notion of direct and indirect instances:This is alluded to in the meta-model as the requirement that“an instance is an indirect instance of...any of its ancestors”[OMG99],page2-56.UML also places standard constraints on subclasses.The default constraint is that a set of generalizations are disjoint,i.e.“(an)instance may have no more than one of the given children as a type of the instance”[OMG99],page2-35.Abstract classesMeta-Modelling Semantics of UML51Figure4.1Fragment of the core relationships packageenforce a further constraint,which implies that no instance can be a direct instance of an abstract class.We now examine whether these properties are adequately specified in the UML semantics document.In this paper,we will only consider properties that relate to Classifiers:the UML term for any model element that describes behavioural and structural features.Classes are a typical specialisation of Classifiers.4.2EXISTING FORMAL DEFINITIONSFrance et al.[BR98]have defined a formal model of generalization thatfits very well with that adopted in UML.Classes are denoted by a set of object references, where each reference maps to a set of attribute values and operations.generalization implies inheritance of attributes and operations from parent classes(as expected).In addition,class denotations are used to formalise the meaning of direct and indirect instances,disjoint and abstract classes.This is achieved by constraining the sets of52Chapter4Figure4.2Fragment of the common behaviour packageobjects assigned to classes in different ways depending on the roles the classes play in a particular generalization hierarchy.For example,assume that ai is the set of object references belonging to the class a,and b and c are subclasses of a.Because instances of b and c are also indirect instances of a,it is required that bi ai and ci ai, where bi and ci are the set of object references of b and c.Thus,a direct instance of b or c must also be an indirect instance of a.A direct instance is also distinguishable from an indirect instance if there does not exist a specialised class of which it is also an instance.This model also enables constraints on generalizations to be elegantly formalised in terms of simple constraints on sets of object references.In the case of the standard ‘disjoint’constraint on subclasses,the following must hold:bi ci,i.e.there can be no instances belonging to both subclasses.For an abstract class,this constraint is further strengthened by requiring that bi and ci partition ai.In other words,there can be no instances of a,which are not instances of b or c.Formally,this is expressed by the constraint:bi ci ai.We will adopt this model in order to assign a precise denotational meaning to generalization/specialization.4.3SYNTAX AND WELL-FORMEDNESSThe abstract syntax of generalization/specialization is described by the meta-model fragment in Figure4.3of the core relationships package:Meta-Modelling Semantics of UML53Generalization discriminator : NameGeneralizableElementisRoot : BooleanisLeaf : BooleanisAbstract : Boolean+generalization+child*1+specialization+parent*1ClassifierClassisAbstract : BooleanFigure4.3Meta-model fragment of Generalization/Specialization The most important well-formedness rule which applies to this model element,and is not already ensured by the class diagram,is that circular inheritance is not allowed. Assuming allParents defines the transitive closure of the relationship induced by self.generalization.parent,which happens to be the set of all ancestors, then it must hold that:context GeneralizableElementnot self.allParents->includes(self)4.4SEMANTICSThe completeness of the semantic formalisation vs.the desired properties of gen-eralization is now examined.We concentrate on determining whether the following properties of generalization are captured in the meta-model:instance identity and conformance.direct and indirect instantiation of classifiers.disjoint and overlapping constraints on sub-classifiers.abstract classes.As noted in Section3.,the UML meta-model already describes a denotational relationship between Classifier and Instance.The meta-model fragment in Figure4.4 describes this relationship.54Chapter4Figure4.4Meta-model fragment for Class and Instance relationship However,unlike the formal model described above,the UML meta-model does not describe the constraints that generalization implies on this relationship.For example, an Instance can be an instance of many classifiers,yet there are no constraints that the classifiers are related.Thus,the meta-model must be strengthened with additional constraints on the relationship between model elements and their denotations.4.5MODEL STRENGTHENINGThefirst aspect of the model to be strengthened relates to the meaning of indirect instances.As stated in Section4.1,an instance of a classifier is also an indirect instance of its parent classifiers.This property,which we term as‘instance conformance’can be precisely stated by placing an additional constraint on the relationship between the instances of a classifier and the instances belong to the classifier’s parents.It is specified as follows:context c:Classifierinvariantc.generalization.parent->forall(s:Classifier|s.instance->includesAll(c.instance))Meta-Modelling Semantics of UML55 This states that the instances of any Classifier,c,are a subset of those belonging to the instances of its parents.4.5.1Direct instances.Given the above property,it is now possible to precisely describe the meaning of a direct instance:context i:InstanceisDirectInstanceOf(c:Classifier):BooleanisDirectInstanceOf(c)=c.allParents->union(Set(c))=i.classifierA direct instance directly instantiates a single class and indirectly instantiates all its parents.This definition is in fact a more precise description of the OCL operation oclIsTypeOf,i.e.context i:InstanceoclIsTypeOf(c:Classifier):BooleanoclIsTypeOf(c)=i.isDirectInstanceOf(c)A similar operation can be used to assign a precise meaning to the OCL operation oclIsKindOf:context i:InstanceoclIsKindOf(c:Classifier):BooleanoclIsKindOf(c)=i.oclIsTypeOf(c)orc.allSupertypes->exists(s:Classifier|i.oclIsTypeOf(s)) Finally,an OCL operation which returns the Classifier from which an instance is directly instantiated from can be defined:context i:Instancedirect:Classifierdirect=i.classifier->select(c|i.isDirectInstanceOf(c)) 4.5.2Indirect instances.Once the meaning of a direct instance is defined,it is straightforward to obtain an OCL operation that returns all the Classifiers that an instance indirectly instantiates.context i:Instanceindirect:Set(Classifier):indirect=i.classifier-Set(i.direct)The set of indirect classes is the difference of the set of all classifiers instantiated by the instance and the direct classifier.4.5.3Instance identity.Unfortunately,the above constraints do not guarantee that every instance is a direct or indirect instance of a related classifier.For example, consider two classifiers that are not related by generalization/specialization.The56Chapter4 current UML semantics do not rule-out the possibility of an instance being instantiated by both classifiers.Thus,an additional constraint must be added in order to rule out the possibility of an instance being instantiated from two or more un-related classes.This is the unique identity constraint:context i:Instanceinvarianti.classifier=i.direct->union(i.indirect)This states that the only classifiers that an object can be instantiated from are either the classifier that it is directly instantiated from or those that it is indirectly instantiated from.4.5.4Disjoint subclasses.Once direct and indirect instances are formalised,it is possible to give a precise description to the meaning of constraints on generalizations (for example the disjoint constraint).The disjoint constraint can be formalised as follows:context c:Classifierinvariantc.specialization.child->forall(i,j:Classifier|i<>j implies i.instance->intersection(j.instance)->isEmpty)This states that for any pair of direct subclasses of a class,i and j,the set of instances of i will be disjoint from the set of instances of j.4.5.5Abstract classes.Finally,the following OCL constraint formalises the re-quired property of an abstract class that it can not be directly instantiated:context c:Classifierinvariantc.isAbstract impliesc.specialization.child.instance->asSet= c.instanceNote,the result of the specialization.child path is a bag of instances belonging to each subclass of c.Applying the asSet operation results in a set of instances.Equating this to to the instances of c implies that all the instances of c are covered by the instances of its subclasses.This,in conjunction with the disjoint property above,implies the required partition of instances.4.6MODEL EXTENSIONThe above definition of the‘disjoint’constraint is adequate provided that it applies across all generalizations,and indeed this is the default assumption in UML.However, UML also permits overlapping constraints to be applied across subclasses as shown in Figure4.5.Meta-Modelling Semantics of UML 57ADC B overlappingFigure 4.5Partly overlapping subclassesHere,instances of C and D may overlap,but they must be disjoint from instances of B (the default disjoint constraint still exists between B and C and B and D ).Thus,the overlapping constraint is viewed as overriding the existing default constraint.Unfortunately,overlapping constraints are not explicitly encoded in the existing semantics.Therefore,it is necessary to extend the meta-model with an explicit over-lapping constraint in order to be able to formalise its meaning.This is shown in Figure4.6.+stereotypeConstraintFigure 4.6Fragment of the meta-model with extended ConstraintHere,overlapping constraints are modelled as a subclass of Constraint .Because overlapping constraints must be applied across more than one subclass,the following additional well-formedness rule must be added:context o :Overlappinginvarianto.constrained ->size >1An improved version of the disjoint constraint can now be given:context c :Classifierinvariant58Chapter4c.specialization->forall(i,j:Generalization|(i<>j andnot(i.hasSameOverlappingConstraint(j)))implies i.child.instance->intersection(j.child.instance)->isEmpty) This states that the instances of two or more generalizations are disjoint unless they overlap.Note that the same overlapping constraint must be applied to the generaliza-tions.The operation hasSameOverlappingConstraint is defined as follows:context i:GeneralizationhasSameOverlappingConstraint(j:Generalization):Boolean hasSameOverlappingConstraint(j)=((i.stereotypeConstraint->asSet)->intersection(j.stereotypeConstraint->asSet)->exists(c:Constraint| c.oclType=Overlapping)) This operation is true if a pair of generalizations share the same overlapping con-straint.This completes the formalisation examples.Although not complete,they indicate the benefits of adopting a denotational emphasis in modelling the UML semantics. In particular,they have provided a much improved understanding of some important aspects of UML.They have also provided a foundation from which to clarify many other aspects of the language,for example,the meaning of the OCL operations oclIsKindOf and oclIsTypeOf.5.CONCLUSIONThis paper has described ongoing work by members of the precise UML group,who are seeking to develop UML as a precise modelling language.By applying previous knowledge and experience in formalising OO concepts and semantic models,it has been shown how important aspects of the current UML semantics can be clarified and made more precise.A formalisation strategy was also described,with the aim that it will act as a template for exploring further features of UML and for developing new proof systems for the standard language.In the longer term,our intention is to give a semantics to the complete notation set, by mapping into the core,extending the core only when there is not already a concept which suffices.Of course one role of semantics is to clarify and remove ambiguities from the notation.Therefore we will not be surprised if wefind that the notation needs to be adjusted or the informal semantics rewritten.However,we will be able to provide a tightly argued,semantically-based recommendation for any change deemed necessary.Some consideration also needs to be given to quality insurance.There are at least three approaches we have identified:1.peer review and inspection。

相关文档
最新文档