收藏 分享(赏)

面向对象分析与设计概述.ppt

上传人:dzzj200808 文档编号:3360457 上传时间:2018-10-18 格式:PPT 页数:92 大小:4.36MB
下载 相关 举报
面向对象分析与设计概述.ppt_第1页
第1页 / 共92页
面向对象分析与设计概述.ppt_第2页
第2页 / 共92页
面向对象分析与设计概述.ppt_第3页
第3页 / 共92页
面向对象分析与设计概述.ppt_第4页
第4页 / 共92页
面向对象分析与设计概述.ppt_第5页
第5页 / 共92页
点击查看更多>>
资源描述

1、面向对象分析与设计,第一章 面向对象方法概论,1,2,软件系统开发方法,传统开发方法,面向对象方法,直接写程序,结构化分析法,信息建模法,功能能分解法,数据流法,有限状态机法,基于规则系统,E-R图,人工智能,专家系统,抽象,客户,委托,信息隐藏,封装,数据抽象,过程抽象,消息通信,泛化继承,分类,代理,动态行为,静态行为,行为分析,复杂性控制,包括,包括,包括,包括,包括,包括,包括,包括,包括,使用,使用,用于,原则,原则,原则,原则,原则,原则,原则,原则,包括,包括,包括,包括,包括,包括,包括,Contents,3,内容,1.问题提出,2.OO思想与OO程序,3.OO概念与原则,4.

2、 OO优点,面向对象方法概论 Object Oriented Method,Problem of Software Dvpt,11 传统开发方法中存在的问题,二十世纪六十年代以前 软件系统:较小 ,相对简单 编程语言:十分简单(Fortran, Cobol等 ) 崇尚程序员的个人技能 代码:含GOTO语句,随意跳转 随着软件复杂性的增长 代码维护 无开发方法可言,5,1、功能分解法(起于二十世纪七十年代),功能分解法(function decomposition)功能分解 功能+子功能 +功能接口 以系统需要提供的功能为中心来组织系统。 定义各种功能 把功能分解为子功能 同时定义功能之间的接口

3、 对较大的子功能进一步分解,直到可给出明确的定义。 设计数据结构和算法。,6,C语言案例,“程序设计的实质是对确定的问题选择一种好的结构,加上设计一种好的算法。”严蔚敏. 数据结构 案例: 1.0 学生成绩信息管理.C 1.1.1 prog1.c 与1.1.2 prog2.c,7,8,优点,计算机应用普及 特定的用户按自己的需要,对软件系统做出了功能性的要求,有据可寻。 在相当大的程度上,解决了以前存在的问题 特别是与模块化编程结合使用,效率更高 删除GOTO语句,与模块化编程相结合 使得软件能得到有效的维护 适用于功能稳定的应用领域 如某些科学计算 直接地反映用户的需求 工作很容易开始,9,

4、缺点,结构化分析和设计注重处理功能 对所处理的数据放于次要的位置 对于众多的领域而言,其功能是易变的 如企业管理和商业管理。 对需求变化的适应能力很差。 局部的错误和局部的修改很容易产生全局性的影响。 开头容易,结束难。 不能直接地映射问题域 很难检验分析结果的正确性。,10,2、数据流法(结构化分析法,二十世纪七十年代),数据流法 数据流数据处理(加工)数据存储端点处理说明数据字典 基本策略 跟踪数据流,问题域被映射为数据流图(DFD) 用处理说明和数据字典进行详细说明。,11,经过初步的需求分析,得到系统功能要求: 1、监视病员的病症(血压、体温、脉搏等)。 2、定时更新病历。 3、病员出

5、现异常情况时报警。 4、随机地产生某一病员的病情报告。,数据流图案例:医院病房监护系统,监视病情,更新病历,辅助图例:,四种基本图形符号:,数据流图的图符,系统功能要求:1、监视病员的病症(血压、体温、脉搏等)2、定时更新病历3、病员出现异常情况时报警。4、随机地产生某一病员的病情报告。,顶层:,顶层设计:案例:医院病房监护系统,图 215,图 216,医院病房监护系统分层DFD图,数据流法业务模型优缺点,优点: 有严格的法则,逐步求精,较强调研究问题域。 缺点: 在概念上,不能直接地映射到问题域中的事物 对需求变化的适应能力较弱。 大系统数据流和加工的数量太多,引起分析文档的膨胀。 系统复杂

6、时,难以检验分析的正确性。 分析与设计的概念和表示法不一致,其转换规则也不严格。,16,小结,功能分解法和数据流法 适用于功能稳定的应用领域,如某些科学计算 已经开发了很多软件系统。 对于功能易变的众多领域,如企业管理和商业管理领域 容易导致模块的低内聚和模块间的高耦合 使得统缺乏灵活性和可维护性。 由于当时团队的开发与管理方法不足 20世纪70年代,软件危机情况更加严重。 解决软件危机方法 对开发技术进行了一定的改进 对编程语言进行了革新 如产生了用于软件开发的4GL、CASE工具、原型技术和代码生成器 这些努力取得了一定的成就,但没有从根本上解决问题。,17,3、基于数据的方法(二十世纪八

7、十年代),实体-联系图 用实体的数据集合作为构造块,以数据结构为中心。 信念 数据是“企业应用”中最稳定的部分 背景 关系数据库有一个极好的数学基础 大多数公司使用数据建模方法开发软件。 结构化的方法实际上能够帮助开发者处理数据 但数据建模方法却不能帮助开发者管理功能。,18,信息建模法(information modeling),信息建模 实体(对象)属性关系父类型子类型关联对象由实体-联系法(E-R方法)发展而来。 与数据库设计有很深的渊源。 核心概念是实体和联系: 实体描述问题域的事物,含有属性; 联系描述事物之间在数据方面的关系,也可以带有属性。 实体称作对象 使用类型和子类型的概念,

8、作为实体(对象)的抽象描述。,19,业务模型,实体(对象) 属性 联系 父类型/子类型 关联对象,跟踪数据流,从而发现数据流和加工。,强调对信息实体建模,而不是对象建模。 对象只有属性,而无操作。 父类与子类之间也只有属性继承。 没采用消息通讯。,1,4、有限状态机方法,基于现实的行为视图 状态系统的构造块 所操作的数据独立于状态 基于系统状态的处理 这一方法没有说到数据管理。,21,预订,归档,使用,确认,等待,机票初始状态,5、基于规则的系统,计算机是执行一套规则的推理机(ifthen语句)。 基于人工智能系统 没有帮助我们处理数据 不支持过程概念 如 prolog, list语言 ,22

9、,传统开发方法总结,上述方法都仅基于一个角度看待系统 对系统的其它视图建模方面的能力很弱。 对OO产生都做出了一定的贡献.,23,Contents,24,内容,1.问题提出,2.OO思想与OO程序,3.OO概念与原则,4. OOD优点,面向对象方法概论 Object Oriented Method,Basic Idea of OO,12 面向对象的基本思想,功能分解法 集中于将功能作为系统的构造块 数据分析方法(实体联系模型) 构造块是实体 忽略了满足系统需求的功能 功能分解法与数据分析方法存在问题: 没有处理对动态行为的捕获 忽略了声明性语义(规则)以及例外处理机制 八十年代中后期:出现较为

10、完善的面向对象分析和设计方法 从多个视角同时捕获系统功能、行为、实体,26,一切都是对象,27,例题:编写一个开发票程序,需要对发票的名细栏进行计算。,非面向对象思路:定义数据结构定义函数,面向对象思路:,对象 一组属性 操作:发票总计,什么是面向对象,28,从程序设计方法的角度看,面向对象是一种新的程序设计范型(paradigm),其基本思想是使用对象、类、继承、封装、聚合、关联、消息、多态性等基本概念来进行程序设计。,从方法学的角度看,面向对象方法是一种运用对象、类、继承、封装、聚合、关联、消息、多态性等概念来构造系统的软件开发方法。,面向对象的基本思想,直接以问题域(现实世界)中的事物为

11、中心来思考问题、认识问题 根据这些事物的本质特征,把它们抽象地表示为系统中的对象,作为系统的基本构成单位。 使系统直接映射问题域,保持问题域中事物及其相互关系的本来面貌(对象) 用对象的属性表示事物的性质; (属性) 用对象的操作表示事物的行为。(操作) 对象的属性与操作结合为一体 对外屏蔽其内部细节。(对象的封装),29,面向对象的基本思想(Cont.),对事物进行分类。 把具有相同属性和相同操作的对象归为一类,类是这些对象的抽象描述,每个对象是它的类的一个实例。 (分类) 复杂的对象可以用简单的对象作为其构成部分。(聚合) 通过在不同程度上运用抽象的原则,可以得到较一般的类和较特殊的类。

12、特殊类继承一般类的属性与操作,从而简化系统的构造过程及其文档。(继承) 类具有封闭性,把内部的属性和操作隐藏起来 只有公共的操作对外是可见的。 (类的封闭性) 对象之间通过消息进行通讯 实现对象之间的动态联系。 (消息) 通过关联表达类(一组对象)之间的静态关系。(关联),30,客观世界,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象名 属性 操作 ,类,类,类,类,分类,类,继承,类,类,对象,聚合,抽象 客观事物及其间的联系,关联,用况图,类图,顺序图,状态图,活动图,构件图,OO模型,编程,构成,封装,运行,分析,设计,面向对象的基本思想示意图,对象,对象,对象,对象,

13、对象,对象,对象,对象,计算机内的对象,OO Programming,Procedural Programming - Example,A procedural programming language usually consists of :A collection of variables, each of which at any stage contains a certain value (a number, a character, a string of characters, etc)A collection of statements that change the val

14、ues of these variables. The building-block of this type program is the procedure or function.,Programs = Algorithm + Data Structure,Object-Oriented Programming - Example,Object-Oriented approachcombine the accounts (data) with the operations on the accounts to objects. A new kind of data type: BankA

15、ccount class C+ code:,Class BankAccount private:float balance;float interestYTD;char * owner;int account_number;public:void Deposit (float amount) .float WithDraw (float amount) bool Transfer (BankAccount ,Object-Oriented Programming - Example,The building-block of this type program is class or obje

16、cts.,C+案例(计算机内的对象),1.2 student_class.cpp 1.3 construct_class.cpp 1.4 construct_class_1.cpp 1.5 overload.cpp 1.6 overload.cpp 1.7 hierarchy.cpp 1.8 hierarchy.cpp,36,Java案例(计算机内的对象),引用:PassTest.java 重载:methodoverloadingtest 多态:geometrydemo 永久对象:JDBC,37,Contents,38,内容,1.问题提出,2.OO思想与OO程序,3.OO概念与原则,4. OO

17、优点,面向对象方法概论 Object Oriented Method,Basic concepts of OO,Basic Concepts of Object Orientation,Object 对象Class 类Message 消息 association关联 aggregation聚合Basic Principles of Object Orientation 面向对象的基本原则Abstraction 抽象Encapsulation 封装Inheritance 继承Polymorphism 多态Interface and Abstract Class 接口与抽象类 行为分析 复杂性控制

18、,What Is an Object?,Informally, an object represents代表 an entity实体, either physical, conceptual, or software.Physical物理 entity Conceptual概念 entity Software软件 entity,Chemical Process,A More Formal Definition正式的定义,An object is an entity with a well-defined明确定义 的boundary边界 and identity 标识 that encapsul

19、ates state状态 and behavior行为. State is represented by attributes 属性and relationships关系. Behavior is represented by operations操作, methods方法, and state machines状态机.,Object,Operations,Attributes,An Object Has State状态,The state of an object is one of the possible conditions 可能的状况 in which an object may e

20、xist. The state of an object normally changes over time随着时间而变化.,Name: J Clark Employee ID: 567138 HireDate: 07/25/1991 Status: Tenured Discipline: Finance MaxLoad: 3,Name: J Clark Employee ID: 567138 Date Hired: July 25, 1991 Status: Tenured 终身的 Discipline: Finance Maximum Course Load: 3 classes,Pro

21、fessor Clark,An Object Has Behavior行为,Behavior determines决定 how an object acts and reacts行为与反应. The visible可见的 behavior of an object is modeled建模 by the set of messages it can respond to 可以响应(operations the object can perform对象能够执行的操作).,Professor Clarks behavior Submit Final Grades Accept Course Off

22、ering Take SabbaticalMaximum Course Load: 3 classes,SubmitFinalGrades(),AcceptCourseOffering(),TakeSabbatical(),Professor Clark,SetMaxLoad(),An Object Has Identity标识,Each object has a unique identity唯一标识, even if the state is identical to that of another object.,Professor “J Clark” teaches Biology,P

23、rofessor “J Clark” teaches Biology,Objects Need to Collaborate合作,Objects are useless unless they can collaborate together to solve a problem. Each object is responsible for its own behavior and status. No one object can carry out 执行every responsibility责任 on its own独自. How do objects interact相互作用 wit

24、h each other? They interact through messages.,What Is a Class?,A class is a description of a set of一组 objects that share the same properties and behavior. An object is an instance of a class.,Class: Professor,Attributes,Operations,A Sample Class,Data Items: manufacturers name制造商 model name产品型号 year

25、made color number of doors size of engine发动机 etc.,Methods: Define data items (specify 指定manufacturers name, model, year, etc.) Change a data item (color, engine, etc.) Display data items Calculate cost etc.,Class: Automobile,The Relationship Between Classes and Objects,A class is an abstract definit

26、ion of an object. It defines the structure and behavior of each object in the class. It serves as a template模板 for creating objects Objects are grouped into分组 classes. An object is an instance实例of a class.,Objects,From Real World,abstracting,Class: Professor,To computer World,instancing,Objects,What

27、 Is an Attribute属性?,An attribute is a named property of a class that describes a range of values一套变量 instances of the property may hold. A class may have any number of attributes or no attributes at all.,Attributes,Attributes in Classes and Objects,name: M. Modano address: 123 Main studentID: 9 date

28、ofBirth: 03/10/1967,name: D. Hatcher address: 456 Oak studentID: 2 dateofBirth: 12/11/1969,Class,Objects,What Is an Operation?,An operation is the implementation of a service that can be requested from any object of the class to affect behavior. A class may have any number of operations or none at a

29、ll.,Operations,Example: class Professor,Example : Instance of Professor,What is a message?,A specification规格 of a communication between objects that conveys传输 information with the expectation期望 that activity行动 will ensue跟着发生 One object asks another object to perform an operation.,wang.getName(),What

30、 is your name?,Example: Object Interaction,The OrderEntryForm wants Order to calculate the total dollar value for the order.,OrderEntryForm,Order,orderID date salesTotal tax shipDate,CalculateOrderTotal(),calculateOrderTotal(),The class Order has the responsibility to calculate the total dollar valu

31、e.,Message,Basic Principles原则 of Object Orientation,What Is Abstraction?,Abstraction can be defined as:Any model that includes the most important重要的, essential基本的, or distinguishing区分的 aspects of something while suppressing抑制 or ignoring 忽略less important, immaterial不重要的, or diversionary转移注意力的 detail

32、s. The result of removing distinctions区别 so as to emphasize commonalties共同点. (Dictionary of Object Technology, Firesmith, Eykholt, 1995) Abstraction Emphasizes relevant characteristics. Suppresses other characteristics.,Example: Abstraction,Student,Professor,Course Offering (9:00 AM, Monday-Wednesda

33、y-Friday),Course (e.g. Algebra),What Is Encapsulation?,Encapsulation means to design设计, produce生产, and describe描述 software so that it can be easily used 使用without knowing the details细节 of how it works. Also known as information hiding信息隐藏An analogy类比: When you drive a car, you dont have to know the

34、details of how many cylinders 汽缸the engine has or how the gasoline汽油 and air空气 are mixed and ignited点燃. Instead相反地 you only have to know how to use the controls.,What Is Encapsulation?,Improves Resiliency弹性,Hide implemmentation实现 from clientsclients depend on interface,Encapsulation Illustrated举例说明,

35、Professor Clark needs to be able to teach four classes in the next semester.,SubmitFinalGrades(),AcceptCourseOffering(),TakeSabbatical(),Professor Clark,SetMaxLoad(),Name: J Clark Employee ID: 567138 HireDate: 07/25/1991 Status: Tenured Discipline: Finance MaxLoad:4,SetMaxLoad(4),Encapsulation Infor

36、mation/Implementation hiding,Interface,Implementation details which are unvisuable for client.,Information which cant be accessed by client,Client,Deposit() Withdraw() Transfer(),Balance insterestYTD Owner Account_numberDeposit() Withdraw() Transfer() ,What Is Inheritance ?,Inheritance a way of orga

37、nizing classes Term术语 comes from inheritance of traits特征 like eye color, hair color, and so on. Classes with properties in common can be grouped so that their common properties are only defined once.Is an “is a kind of” relationship,An Inheritance Hierarchy层级,What properties does each vehicle inheri

38、t from the types of vehicles above it in the diagram?,Example: Single Inheritance单继承,One class inherits from another.,Checking,Savings,Superclass (parent),Subclasses,Inheritance Relationship,Ancestor,Descendents,Example: Multiple Inheritance多重继承,A class can inherit from several other classes.,Use mu

39、ltiple inheritance only when needed and always with caution!,Multiple Inheritance,Polymorphism多态性,Polymorphismthe same word or phrase can be mean different things in different contexts不同情境下的不同东西 Analogy: in English, bank can mean side of a river or a place to put money In Java, two or more classes c

40、ould each have a method called output Each output method would do the right thing for the class that it was in. One output might display a number数字 whereas a different one might display a name名字.,What Is Polymorphism?,The ability to hide many different implementation behind a single interface.,OO Pr

41、inciple: Encapsulation,Example: Polymorphism,Stock股票,Bond债券,Mutual Fund共有基金,Get Current Value,getCurrentValue(),getCurrentValue(),getCurrentValue(),Realization relationship,(stay tuned for realization relationships),What is an Interface?,An interface is a collection of operations that specify a serv

42、ice of a class or component. Interfaces formalize polymorphism Interfaces support “plug-and-play” architectures,Shape,draw(),move(),scale(),rotate(),Tube,Pyramid,Cube,What,How,Elided省略/Iconic图标 Representation (“lollipop”棒棒糖),Canonical标准的 (Class/Stereotype) Representation,(stay tuned for realization

43、relationships),How Do You Represent An Interface?,Shape,draw(),move(),scale(),rotate(),Shape,What is an Abstract Class?,An abstract class is a class that may not has any direct instances. In the UML, a class is abstract by writing its name in italics. An abstract operation is an operation that it is

44、 incomplete未完成的 and requires a child子类 to supply an implementation 实现of the operation. In the UML, an abstract operations name is italics.,Contents,74,内容,1.问题提出,2.OO思想与OO程序,3.OO概念与原则,4. OO优点,面向对象方法概论 Object Oriented Method,14 面向对象方法的主要优点,75,从认识论的角度看,面向对象方法改变了人们认识世界的方式 从计算机语言发展角度看,缩短了自然语言到计算机语言的鸿沟 从软

45、件工程角度看,缩小了问题域到问题解决域(计算机)的鸿沟 面向对象程序设计有助于软件的维护与复用 面向对象方法有助于提高软件的质量和生产率,76,对问题域的认识(人),客观世界 (问题域),计算机,自然语言,语 言 的 鸿 沟,编程语言,语言的过渡(人),编程(人),程序的理解 和执行(机器),软件开发:从问题域出发,对事物进行认识和描述问题语言的鸿沟,认识论角度:改变了人们认识世界的方式,14 面向对象方法的主要优点,77,从认识论的角度看,面向对象方法改变了人们认识世界的方式 从计算机语言发展角度看,缩短了自然语言到计算机语言的鸿沟 从软件工程角度看,缩小了问题域到问题解决域(计算机)的鸿沟

46、 面向对象程序设计有助于软件的维护与复用 面向对象方法有助于提高软件的质量和生产率,78,计算机,自然语言,客观世界 (问题域),语言的鸿沟,程序的指令、数据、地址,都是由二进制的“0”和“1”构成的。离机器最近,能够直接地执行,然而没有丝毫形象的意义,离人类的思维最远。,以易理解的符号表示指令、数据以及寄存器、地址等物理概念。稍稍适合人类的形象思维,但仍然相差很远。因为抽象层次太低,仍需考虑大量的机器细节。,高级语言隐蔽了机器细节,使用有形象意义的数据命名和表达式,可以联系到程序所描述的具体事物。特别是结构化编程语言更便于体现客观事物的结构和逻辑涵义,与人类的自然语言更接近,但仍有不少差距。

47、,能比较直接地反映客观世界的本来面目,并使软件开发人员能够运用人类认识事物所采用的一般思维方法来进行软件开发。,语言的发展鸿沟变窄,14 面向对象方法的主要优点,79,从认识论的角度看,面向对象方法改变了人们认识世界的方式 从计算机语言发展角度看,缩短了自然语言到计算机语言的鸿沟 从软件工程角度看,缩小了问题域到问题解决域(计算机)的鸿沟 面向对象程序设计有助于软件的维护与复用 面向对象方法有助于提高软件的质量和生产率,80,问题域,测试,编程,计算机,编程语言,自然语言,需求 分析,总体 设计,详细 设计,软件工程学的作用 结构化的软件工程方法,软件工程角度:从问题域到计算机间的鸿沟变窄,8

48、1,问题域,OOA,计算机,自然语言,面向对象的 编程语言,OOD,OOP,OOT,软件工程学的作用 面向对象的软件工程方法,14 面向对象方法的主要优点,82,从认识论的角度看,面向对象方法改变了人们认识世界的方式 从计算机语言发展角度看,缩短了自然语言到计算机语言的鸿沟 从软件工程角度看,缩小了问题域到问题解决域(计算机)的鸿沟 有助于软件的维护与复用 有助于提高软件的质量和生产率,有助于软件的维护与复用,面向对象程序设计把数据和处理数据的过程作为一个整体,即对象。,83,算法+数据结构,算法+数据结构,算法+数据结构,算法+数据结构,对象,算法+数据结构,对象,对象,对象,对象,关系,程

49、序= 对象=(算法)+(数据结构),结构化程序设计,程序 =,关系,14 面向对象方法的主要优点,85,从认识论的角度看,面向对象方法改变了人们认识世界的方式 从计算机语言发展角度看,缩短了自然语言到计算机语言的鸿沟 从软件工程角度看,缩小了问题域到问题解决域(计算机)的鸿沟 有助于软件的维护与复用 有助于提高软件的质量和生产率,86,有助于提高软件的质量和生产率,软件开发过程各个环节开展质量保证活动 系统好用、易用、可移植和易维护,用户满意 OO技术从分析到编程阶段能提高效率20% 在维护阶段(完善性维护、纠错性维护、适应性维护、预防性维护)提高得就更多: 设计的投入在编程、测试时会得到回报 OO方法使系统更易于理解 分析文档、设计文档、源代码对应良好 功能变化引起的全局性修改较少 有利于OOA结果的复用,

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

当前位置:首页 > 高等教育 > 大学课件

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报