uml对象技术与可视化建模基础.ppt

上传人:牧羊曲112 文档编号:5451570 上传时间:2023-07-08 格式:PPT 页数:99 大小:1.70MB
返回 下载 相关 举报
uml对象技术与可视化建模基础.ppt_第1页
第1页 / 共99页
uml对象技术与可视化建模基础.ppt_第2页
第2页 / 共99页
uml对象技术与可视化建模基础.ppt_第3页
第3页 / 共99页
uml对象技术与可视化建模基础.ppt_第4页
第4页 / 共99页
uml对象技术与可视化建模基础.ppt_第5页
第5页 / 共99页
点击查看更多>>
资源描述

《uml对象技术与可视化建模基础.ppt》由会员分享,可在线阅读,更多相关《uml对象技术与可视化建模基础.ppt(99页珍藏版)》请在三一办公上搜索。

1、UML建模语言及工具,第 2 章对象技术与可视化建模基础An Overview of Object Technology and Visual Modeling,-3-,Review:An Approach to the Object-Oriented,上升到面向对象面向对象技术概述定义、利益、研究内容面向对象技术发展历史(里程碑)、现状、未来面向对象与结构化扬弃而非否定上升到面向对象利用面向对象的观点认识客观问题,-4-,学习线路图,-5-,Agenda 1,Object and ClassFour Principles of OOGeneralization and Polymorphis

2、mPrinciples of Visual ModelingThe UMLProcess and visual modeling,-6-,Object,Informally,an object represents an entity,either physical,conceptual,or softwarePhysical entityConceptual entitySoftware entity,化学过程,-7-,Object-Formal Definition,An object is an entity with a well-defined boundary and identi

3、ty that encapsulates state and behavior.State is represented by attributes and relationships.Behavior is represented by operations,methods,and state machines.,-8-,对象的标识,每一个对象都有一个唯一的标识,即使其状态有可能与其它对象一样,班机 747 on 11/10,班机 747 on 11/11,班机 747 on 11/12,-9-,对象的标识,Professor“J Clark”teaches Biology,Professo

4、r“J Clark”teaches Biology,-10-,对象的状态,一个对象的状态是它反映于现实世界的一系列属性:参数的数值(也就是,与对象有关系的数据)它与其它对象的关系,可能的状态:停泊 运营着陆 终止,班机 747,-11-,对象的状态,State is a condition or situation during the life of an object,which satisfies some condition,performs some activity,or waits for some event.The state of an object normally ch

5、anges over time.,Name:J ClarkEmployee ID:567138Date Hired:July 25,1991Status:TenuredDiscipline:FinanceMaximum Course Load:3 classes,Name:J ClarkEmployee ID:567138HireDate:07/25/1991Status:TenuredDiscipline:FinanceMaxLoad:3,Professor Clark,-12-,对象的行为,定义当其它对象发出请求时,该对象如何反应由为对象定义的一系列操作决定,-13-,对象的行为,Beha

6、vior determines how an object acts and reacts.The visible behavior of an object is modeled by a set of messages it can respond to(operations that the object can perform).,Professor Clark,Professor Clarks behaviorSubmit Final GradesAccept Course OfferingTake Sabbatical Set Max Load,SubmitFinalGrades(

7、),AcceptCourseOffering(),TakeSabbatical(),SetMaxLoad(),-14-,Sample-An Object,-15-,Representing Objects in the UML,An object is represented as a rectangle with an underlined name.,Named Object,Anonymous Object,-16-,Class,A class is a description of a set of objects that share the same attributes,oper

8、ations,relationships,and semantics.An object is an instance of a class.A class is an abstraction in that it Emphasizes relevant characteristics.Suppresses other characteristics.,-17-,Sample-A Class,ClassEmployee,PropertiesNameAddressPositionSalaryStart DateEnd Date,BehaviorHireFirePromoteIncrease Sa

9、laryRetire,-18-,Representing Classes in the UML,A class is represented using a rectangle with compartments.,属性,操作,具有相同特征和操作的对象可以放到类中。在下面这副图中您看到了什么类?,类,对象的类,您看到了几个类?,-21-,属性,属性是类的特征或特性属性的值是某一特定对象的属性值在类中属性名必须是唯一的每一个类的实例都有为这个类定义的所有属性的值,银行帐户类属性帐号银行名称拥有者金额,Mary的银行帐户属性值12345678First National BankMary Smit

10、h$1024.48,-22-,属性取决于视点,从销售人员的角度 型号 价格 颜色 里程数,一辆汽车具有的属性:,从维修人员的角度 马达类型 传动类型 维修记录,-23-,操作,对象的行为是由为此对象定义的一系列操作决定的操作访问或修改对象的属性值一个类可能同时存在多个实例,也可能在某一时刻没有实例一个类的所有实例都可以使用在这个类中定义的操作,-24-,类和对象,对象,实体,类,抽象数据类型,计算机世界,实例化,抽 象,映 射,映 射,现实世界,-25-,类是生成对象的模板,类是生成对象的模板类的定义中包含有产生和删除对象的操作一个类定义了使用哪种数据表示法来描述属性每一个实例都采用有属性值的

11、数据表示法一个类通过一系列操作来定义行为这种操作能在每个实例中激活,班机,-26-,类和对象的关系,每一个对象都是某一个类的实例每一个类在某一时刻都有零个或更多的实例类是静态的;它们的存在、语义和关系在执行前就已经定义好了对象是动态的;它们在程序执行时可以被创建和删除,-27-,Sample-Object and Class,现实世界中的学生对象和对Student类的建模,Bob,John,Kate,Beverly,Student属性方法,一些学生对象,Student类,-28-,Agenda-2,Object and ClassFour Principles of OOGeneralizat

12、ion and PolymorphismPrinciples of Visual ModelingThe UMLProcess and visual modeling,-29-,Basic Principles of Object Orientation,-30-,抽象,抽象(abstraction)就是过滤掉对象的一部分特性和操作,直到只剩下所需要的属性和操作。,一些权威认为抽象对于建模者来说是最重要的技术,也就是说要搞清楚什么应该纳入模型中,什么应该舍去。,抽取共同性,例如,准备编制游戏软件,其中需要实现不同人物使用魔法的功能。每个人物具有不同的魔法,并具备使用魔法的行为,抽象得到的人物类

13、图如:,-31-,Example:Abstraction,一个项目的抽象依赖于定义抽象的上下文,-32-,封装性-Encapsulation,Hides implementation from clients.Clients depend on interface.,-33-,封装性,封装(encapsulation)是软件模块化思想的体现,也是面向对象的根本之一封装实现信息隐藏和数据抽象信息隐藏的出发点:对象的私有数据不能被外界存取,只能以合法的手段访问将数据抽象为一组行为,而不是内部的具体数据结构,把用户隔离在细节之外,从而使得软件各个部分依赖于抽象层,各模块获得自由,可以变化细节,可以替

14、换,-34-,Professor Clark needs to be able to teach four classes in the next semester.,SubmitFinalGrades(),AcceptCourseOffering(),TakeSabbatical(),Professor Clark,SetMaxLoad(),Name:J ClarkEmployee ID:567138HireDate:07/25/1991Status:TenuredDiscipline:FinanceMaxLoad:4,SetMaxLoad(4),-35-,为什么要封装,结构化程序设计:程序

15、=算法+数据结构,全局数据,算法,算法,算法,算法,一个大问题:如何保证数据的一致性?,-36-,范例:数据一致性,class ShippingAddress public long cityCode;public String address;,城市代码例如:北京为01上海为02,邮政地址“北京朝阳区静安里6号”,操作这个数据结构的程序员,必须严格遵守一系列业务逻辑规则,否则很容易破坏数据的一致性结构化程序设计处理大项目时,多人协同开发时,本质上无法保证数据的一致性,class ShippingAddress private long cityCode;private string addr

16、ess;public long ModifyAddress(String address),-37-,信息隐藏保证数据一致性,通过信息隐藏:1.外围代码无法随意访问底层数据,只能以合乎规范的方式操作数据2.保证数据一致性的逻辑只需正确开发一次,便可以供所有人反复使用3.业务逻辑知识被局限起来,协同开发难度降低信息隐藏是面向对象更适应大型软件开发的根本原因之一,-38-,数据隐藏的实现:C,文件域内的数据隐藏,粒度太粗/*本文件域的私有数据*/static int use_count=0;void func(int arg)+use_count;C的结构体无数据隐藏机制:struct Simpl

17、eObject_t int myInteger;void(*setInteger)(int);,-39-,数据隐藏的实现:C+,用private访问级别关键字定义私有数据,隐藏内部数据struct SimpleObject private:int myInteger;public:void setInteger(int i);SimpleObject(int i=0):myInteger(i)使用:SimpleObject so(8);so.myInteger=16;/compile errorso.setInteger(16);/OKC+对于对象私有数据的隐藏,完全是靠编译器保证,而由于C+

18、过于强大的指针运算能力,编译器很容易被欺骗,所以,-40-,1#include 2 using namespace std;3 4 5 class A6 7 private:8/a 20,21 int A:GetA()22 23 return a;24 25 26 double A:GetB()27 28 return b;29 30,-41-,31 int _tmain(int argc,_TCHAR*argv)32 33 A test;34 35 cout before pointer access:n36 test.a=test.GetA()n37 test.b=test.GetB()n

19、 endl;38,43/value changing by pointer!44*privateA=1;45*privateB=2.5;46 47 cout after pointer access:n test.a=test.GetA()n test.b=test.GetB()n endl;50 return 0;51,39/access object test of class A by pointer40 int*privateA=reinterpret_cast(42,运行后输出结果为:before pointer access:test.a=0test.b=0after pointe

20、r access:test.a=1test.b=2.5,-42-,Java中的数据隐藏,so,SimpleObject对象实体,int myInteger,void setInteger(int i),虽然so本身也是指针(在Java里叫做引用reference),但是Java没有提供任何指针运算,因此无法骗过编译器,能够完全保证私有成员数据不被非法访问。,-43-,模块性-Modularity,Breaks up something complex into manageable piecesHelps people understand complex systemsCohesion(内聚

21、),Coupling(耦合)Class,Component,Package,-44-,模块化例子,For example,break complex systems into smaller modules.,-45-,Package,A general purpose mechanism for organizing elements into groupsA model element that can contain other model elements.A package can be used:To organize the model under development.As

22、a unit of configuration management.,-46-,A Package Can Contain Classes,The Package,University Artifacts,contains one package and five classes,-47-,层次性-Hierarchy,Any ranking or ordering of abstractions into a tree-like structure Types of Hierarchy:Inheritance,Aggregation,Increasingabstraction,Decreas

23、ingabstraction,Elements at the same level of the hierarchy should be at the same level of abstraction,-48-,Agenda-3,Object and ClassFour Principles of OOGeneralization and PolymorphismPrinciples of Visual ModelingThe UMLProcess and visual modeling,-49-,Generalization,A relationship among classes whe

24、re one class shares the structure and/or behavior of one or more classesDefines a hierarchy of abstractions in which a subclass inherits from one or more superclassesSingle inheritanceMultiple inheritanceIs an“is a kind of”relationship.,-50-,范例:单一继承,One class inherits from another,-51-,范例:多重继承,A cla

25、ss can inherit from several other classes,Use multiple inheritance only when needed and always with caution!,-52-,What Is Inherited?,A subclass inherits its parents attributes,operations,and relationshipsA subclass may:Add additional attributes,operations,relationshipsRedefine inherited operations(U

26、se caution!)Common attributes,operations,and/or relationships are shown at the highest applicable level in the hierarchy,-53-,范例:继承什么?,class Student protected string name;public string getName()public Account theAccount;class GraduateStudent extends Student 派生类(子类)从基类(超类、父类)中派生,继承了基类中全部的public和prote

27、cted数据成员和方法。所以即使GraduateStudent中没有定义getName(),也会从Student中得到getName()方法的全部实现派生类也会继承基类中的关系,因此GraduateStudent与Account也有聚合关系,-54-,继承的原始目的,在面向对象思想发展的初期,通过继承复用代码曾经被认为是面向对象最重要的目标之一当时人们的想法是:从基类获得大部分成熟的代码,实现主要的功能,而修改必要的部分,实现特色功能很遗憾,实践中人们发现无法达成事先预期的效果,-55-,继承并非代码复用的最佳机制,继承在代码复用方面不如其它方式灵活有效比如函数库代码复用在今天的意义不象先前预

28、期的那么大,原因是:代码只是细节,系统由接口定义。另外软件开发的人力资源越来越丰富,开发难度大幅降低但是继承所提供的代码复用仍然是一项重要的“福利”,应当善加利用今天继承的主要意义在于为实现多态铺平了道路,-56-,What Is Polymorphism?,The ability to hide many different implementations behind a single interface,-57-,范例:多态,abstract class Shape public abstract void draw();class Rectangle extends Shape/覆盖(

29、override)基类方法 public void draw()./*绘制矩形*/class Circle extends Shape/覆盖(override)基类方法 public void draw()/*绘制圆形*/,-58-,虚函数多态,class Shape public:virtual void Draw(void);class Circle:public Shapepublic:virtual void Draw(void);class Sphere:public Shapepublic:virtual void Draw(void);,void DrawShape(Shape*

30、aShape)aShape-Draw();main()Shape aShape;Circle aCircle;Sphere aSphere;DrawShape(,-59-,应用多态性,假设我们有一个数组sharr,里面放着一排Shape,但是不知道哪些是Rectangle,哪些是Circle。利用多态性,我们可以:for(int i=0;i sharr.length;+i)Shape shape=(Shape)sharri;shape.draw();遍历整个数组的过程中,各个Shape自己知道应当如何在画布上绘制自己。shape.draw()这同一行代码在shape指向不同的对象时表现出不同的

31、行为,这就是所谓多态性,-60-,Agenda-4,Object and ClassFour Principles of OOGeneralization and PolymorphismPrinciples of Visual ModelingThe UMLProcess and visual modeling,-61-,What Is a Model?,A model is a simplification(简化)of reality,-62-,Why Model?,Modeling achieves four aims:Helps you to visualize a system as

32、 you want it to be.Permits you to specify the structure or behavior of a system.Gives you a template that guides you in constructing a system.Documents the decisions you have made.You build models of complex systems because you cannot comprehend such a system in its entiretyYou build models to bette

33、r understand the system you are developing,-63-,建模的意义,模型是对现实的简化,建模是为了更好地理解系统。模型帮助我们按照实际情况或需求对系统可视化;(掌握不了文字,画幅画代替)模型允许我们详细说明系统的结构、行为;模型给出了一个构造系统的模板;模型对我们作出的决策进行文档化。(先有文档,再有代码),-64-,The Importance of Modeling,Paper Airplane,Fighter Jet,Less Important,More Important,-65-,Principle 1:The Choice of Model

34、 Is Important,The models you create profoundly influence how a problem is attacked and how a solution is shapedIn software,the models you choose greatly affect your world viewEach world view leads to a different kind of system,-66-,Principle 2:Levels of Precision May Differ,Every model may be expres

35、sed at different levels of precision(精度)The best kinds of models let you choose your degree of detail,depending on:Who is viewing the modelWhy they need to view it,-67-,Principle 3:The Best Models Are Connected to Reality,All models simplify realityA good model reflects potentially fatal characteris

36、ticsThe trick is to be sure that your simplifications dont mask any important details.A good model reveals any potentially fatal flaws in design,-68-,Principle 4:No Single Model Is Sufficient,No single model is sufficient.Every non-trivial system is best approached through a small set of nearly inde

37、pendent models.Create models that can be built and studied separately,but are still interrelated,-69-,建模的原理,选择创建什么模型对如何动手解决问题和如何形成解决方案有意义深远的影响。三只小猪盖房子 摩天大厦每一种模型可以在不同的精度级别上表示。最好的模型可以让你根据观察的角色及原因选择它的详细程度。对每个系统最好用一组几乎独立的模型去处理。飞机模型,-70-,Agenda-5,Object and ClassFour Principles of OOGeneralization and Po

38、lymorphismPrinciples of Visual ModelingThe UMLProcess and visual modeling,-71-,The UML,UMLYou Must LearnUMLUnified Modeling LanguageUML是一种标准的图形化建模语言,它是面向对象分析与设计的一种标准表示,它:不是一种可视化的程序设计语言,而是一种可视化的建模语言不是工具或知识库的规格说明,而是一种建模语言规格说明,是一种表示的标准不是过程,也不是方法,但允许任何一种过程和方法使用它,-72-,What Is the UML?,The UML is a langua

39、ge forVisualizingSpecifyingConstructingDocumenting the artifacts of a software-intensive system,Unified Modeling Language(统一建模语言)是对象管理组织(OMG)制定的一个通用的、可视化的建模语言标准,可以用来可视化(visualize)、描述(specify)、构造(construct)和文档化(document)软件密集型系统的各种工件(artifacts,又译制品),-73-,UML是标准的符号,1.用UML画图很容易,摆脱符号烦恼,全心面对问题,2.UML仅仅是一种表

40、达形式,用好UML首先需要掌握OOAD的基本原则和方法,并在一定的软件开发过程(如统一过程UP/USDP/RUP、XP等)的指导下进行有取舍的运用,但知道要画什么是困难的!,-74-,选择UML-1,Martin Flower:如果你正在使用其它的旧技术,我强列建议您马上转用UML,因为它明显地将成为符号系统的统一标准。如果你正在考虑开始使用设计符号来工作,UML是一个好的选择,因为它已经统治业界了,-75-,选择UML-2,UML不是万能的,很多场合并不适合使用1)传统的做法已完全适用,对OOAD的要求也不高,项目非常成功,无任何改进的必要2)开发的系统比较简单,直接用源码配上少量的文字就能

41、解决问题,软件开发文档也无需添加图形来辅助说明3)开发人员更习惯于直接阅读源码,用源码交流,这样做不影响工作效率和质量4)开发的系统本身不属于OO方法、UML适用范围,-76-,选择UML-3,很多情况下,推荐使用UML:1)OO方法是项目决定采用的方法论,是整个项目或产品成功的关键2)开发人员感觉用源码说明不了真正的问题,希望利用可视化建模语言简化文档,提高交流效率,准确抓住问题本质3)系统的规模和设计都比较复杂,需要用图形抽象地表达复杂的概念,增强设计的灵活性、可读性和可理解性,以便暴露深层次的设计问题,降低开发风险4)组织希望记录已成功项目、产品的公共设计方案,在开发新项目时可以参考、重

42、用过去的设计,以节省投入,提高开发效率和整体成功率5)有必要采用一套通用的图形语言和符号体系描述组织的业务流程和软件需求,促进业务人员、软件开发人员之间一致、高效的交流,-77-,UML发展背景,面向对象建模语言产生于1970年代中期1990年代初,建模语言数量达到50多种众多语言各有千秋,缺乏通用性语言之间的细小差别妨碍了用户的交流1990年代中期,三位主要的OO建模大师:Booch,Rumbaugh,Jacoson开始致力于建立统一建模语言的工作,-78-,三位面向对象大师,-79-,UML诞生,公众反馈,OOPSLA95 Unified Method 0.8,工业化标准化统一化分散的各部

43、分,Booch93 OMT-2,1996.6和1996.10 UML 0.9&0.91,1997.9公布 UML 1.1,1997.1公布 UML 1.0,合作伙伴意见,UML 1.1被OMG 接纳为标准,Booch91 OMT-1 其他方法 OOSE,-80-,UML统一,-81-,Agenda-6,Object and ClassFour Principles of OOGeneralization and PolymorphismPrinciples of Visual ModelingThe UMLProcess and visual modeling,-82-,How much yo

44、u can depend on UML?,The UML is nota process or methodologyobject-oriented analysis and designGuidelines(指导、准则)for designMuch more important:Skill in designing with objects.,-83-,A Language Is Not Enough to Build a System,-84-,What Is a Process?,Defines Who is doing What,When to do it,and How to rea

45、ch a certain goal.,-85-,开发过程概述,传统开发过程瀑布模型统一软件开发过程(RUP),-86-,传统开发过程,瀑布模型,Requirements,Analysis,Design,Implementation,Test,Time,-87-,OOAD的开发过程,大项目分解为一些子项目使用UML工具统一软件开发过程(RUP)是一个迭代、递增的开发过程,-88-,RUP的软件开发生命周期,-89-,Overview of the Unified Process,The Unified Process isIterative and incrementalUse case dri

46、venArchitecture-centric,-90-,OOAD的开发过程,Inception Define the scope of the project and develop business case,Elaboration Plan project,specify features,and baseline the architecture,Construction Build the product,Transition Transition the product to its users,-91-,Major Milestones,-92-,Phases and Itera

47、tions,An iteration is a sequence of activities with an established plan and evaluation criteria,resulting in an executable release,-93-,Iterations and Workflow,-94-,Workflows and Models,UML diagrams provide views into each model,Each workflow is associated with one or more models.,-95-,Use Case Mode

48、l,Use CaseDiagrams,CollaborationDiagrams,ComponentDiagrams,DeploymentDiagrams,ObjectDiagrams,StatechartDiagrams,SequenceDiagrams,ClassDiagrams,ActivityDiagrams,-96-,Analysis&Design Model,Use CaseDiagrams,CollaborationDiagrams,ComponentDiagrams,DeploymentDiagrams,ObjectDiagrams,StatechartDiagrams,Seq

49、uenceDiagrams,ClassDiagrams,ActivityDiagrams,Incl.subsystems and packages,-97-,Deployment and Implementation Model,Use CaseDiagrams,CollaborationDiagrams,ComponentDiagrams,DeploymentDiagrams,ObjectDiagrams,StatechartDiagrams,SequenceDiagrams,ClassDiagrams,ActivityDiagrams,Incl.active classes and components,-98-,Test Model,Use CaseDiagrams,CollaborationDiagrams,ComponentDiagrams,DeploymentDiagrams,ObjectDiagrams,StatechartDiagrams,SequenceDiagrams,ClassDiagrams,ActivityDiagrams,Test model refers to all other models and uses corresponding diagrams,-99-,Two Parts of a Unified Whole,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号