?结构化软件开发
?面向对象软件开发
?专家系统软件开发
比较
?从概念方面看
?结构化软件是 功能 的集合,通过模块以及模块
和模块之间的分层调用关系实现;
?面向对象软件是 事物 的集合,通过对象以及对
象和对象之间的通讯联系实现;
?专家系统软件是 知识 的集合,通过知识以及知
识和知识之间的逻辑推理关系实现。
?从构成方面看
?结构化软件=过程+数据,以过程为中心;
?面向对象软件=(数据+相应操作)的封装,
以数据为中心;
?专家系统软件=知识+推理,以知识为中心。
?从运行控制方面看
?结构化软件采用顺序处理方式,由过程驱动控制;
?面向对象软件采用交互式、并行处理方式,由消息驱
动控制;
?专家系统软件采用交互式、并行处理方式,由数据驱
动控制。
?从开发方面看
?结构化方法的工作重点是设计;
?面向对象方法的工作重点是分析;
?专家系统方法的工作重点是知识的获取与表
达。
但是,在结构化方法中,分析阶段和设计阶段采用了
不相吻合的表达方式,需要把在分析阶段采用的具有
网络特征的数据流图转换为设计阶段采用的具有分层
特征的结构图,在面向对象方法中则不存在这一问题。
各种方法特点比较 (Cont.)
?从应用方面看
?结构化方法更加适合数据类型比较简单的数值计
算和数据统计管理软件的开发;
?面向对象方法更加适合大型复杂的人机交互式软
件和数据统计管理软件的开发;
?专家系统方法更加适合逻辑推理型软件的开发。
?从发展方面看
?面向对象方法是软件开发方法的发展方向。
结构化软件开发
分析:问题是什么 设计:怎样解决 实现:解决分析
确定数据流图 (DFD) 建立结构图 (SC) 过程设计
分析确定实体联系图 (ERD) 建立关系数据模式 (RM) 编码调试
运行维护
阅读
?关于结构化软件开发,请阅读, 软件工
程 —实践者的研究方法, ( Software
Engineering-A Practitioner’s Approach)
Chapter 10~14
OO 软件开发技术
Owning a hammer
doesn’t
make one an architect
Outline
?面向对象的概念和原则
?Introduction to Object Technology
?Concepts of Object Orientation
?标识对象模型元素 (UML)
?面向对象软件开发技术
?面向对象分析 (OOA)
?面向对象设计 (OOD)
?面向对象实现 (OOP)
?面向对象的概念和原则
?Introduction to Object Technology
?Concepts of Object Orientation
?表示对象模型元素
?面向对象软件开发技术
?面向对象分析 (OOA)
?面向对象设计 (OOD)
?面向对象实现 (OOP)
面向对象的概念和原则
——Introduction to Object Technology
?What is Object Technology?
? Where is Object Technology used today?
Introduction to OT— What is OT?
? A set of principles (abstraction,
encapsulation,polymorphism)
guiding software construction,
together with languages,
databases,and other tools that
support those principles.
(Object Technology-
A Manager’s Guide,
Taylor,1997.)
Introduction to OT—The Strengths of OT
?Reflects a single paradigm
?Facilitates architectural and code reuse
?Reflects real world models more closely
?Encourages stability
?Is adaptive to change
Introduction to OT—The History of OT
Introduction to OT— Where is OT used today?
Introduction to OT— Where is OT used today?
?面向对象的概念和原则
?Introduction to Object Technology
?Concepts of Object Orientation
?标识对象模型元素
?面向对象软件开发技术
?面向对象分析 (OOA)
?面向对象设计 (OOD)
?面向对象实现 (OOP)
面向对象的概念和原则
——Concepts of Object Orientation
?What is an object?
?Four principles of OO
?What is a class?
?Polymorphism and generalization
?What is Package?
Concepts of OO — Object
?Informally,an object represents an entity,
either physical,conceptual,or software.
?Physical entity
?Conceptual entity
?Software entity
Concepts of OO — Object
?A more formal definition
An object is an entity with a well-defined
boundary and identity that encapsulates
state and behavior.
?State is represented by
attributes and relationships
?Behavior is represented by
operations,methods,and
state machines.
Concepts of OO — Object
? An object has a state
?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 changes over time.
Concepts of OO — Object
?An Object has Behavior
?Behavior 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),
Concepts of OO — Object
?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 Professor,J Clark”teaches biology
Concepts of OO —Four principles of OO
Concepts of OO —Four principles of OO
?What is abstraction?
?The essential characteristics
of an entity that distinguishes
from all other kinds of entities.
?Defines a boundary relative to
the perspective of the viewer
?Is not a concrete manifestation,
denotes the ideal essence of
something.
Concepts of OO —Four principles of OO
?What is Encapsulation?
?Hides implementation from clients.
?Clients depend on interface.
Encapsulation Illustrated
Concepts of OO —Four principles of OO
?What is Modularity?
?Breaks up something complex
into manageable pieces.
?Helps people understand complex
systems.
Concepts of OO —Four principles of OO
?What is Hierarchy?
Concepts of OO — class
?What is a class?
?A class is a description of a set of objects that
share the same attributes,operations,
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
Concepts of OO — class
?Class Compartments
?The class name
?The structure (attributes)
?The behavior (operations)
Concepts of OO —class
?The relationship between Classes and Objects.
?A class is an abstract definition of an object
?It defines the structure and behavior of each object in the
class.
?It serves as a template for creating objects.
?Classes are not collections of objects.
Professor Smith
Professor Panos Professor Joseph
Professor
Concepts of OO — class
?What is an Attribute?
?An attribute is a named property of a class that
describes the range of values that instances of
the property may hold.
?A class may have any number of attributes or no
attributes at all.
Concepts of OO — class
?Attributes in Classes and Objects
Concepts of OO — class
?What is an Operation?
?A service that can be requested from an object to
effect behavior,An operation has a signature,which
may restrict the actual parameters that are possible.
?A class may have any number of operations or none
at all.
Concepts of OO —Polymorphism and generalization
?What is Polymorphism?
?The ability to hide many different
implementations behind a single interface.
Concepts of OO —Polymorphism and generalization
Example:
In this example,a requesting object would like to
know the current value of a financial instrument,
However,the current value for each financial
instrument is calculated in a different fashion,
The stock needs to determine the current asking
price in the financial market that it is listed under,
The bond needs to determine the maturity
timelines and interest rates,A mutual fund
needs to check the day’s closing price from the
fund management company,
Concepts of OO —Polymorphism and generalization
?With object technology
Concepts of OO —Polymorphism and generalization
?What is Generalization?
?A relationship among classes where one
class shares the structure and/or behavior of
one or more classes.
?Defines a hierarchy of abstractions in which a
subclass inherits from one or more
superclasses.
?Single inheritance.
?Multiple inheritance.
?Is an,is a kind of” relationship.
Concepts of OO —Polymorphism and generalization
?What is Inherited?
?A subclass inherits its patent’s attributes,
operations,and relationships.
?A subclass may:
?Add additional attributes,operations,relationships.
?Redefine inherited operations.
?Common attributes,operations,and/or
relationships are shown at the highest
applicable level in the hierarchy.
Concepts of OO —Polymorphism and generalization
?Example,Single Inheritance
?One class inherits from another
(superclass)
(subclass)
Concepts of OO —Polymorphism and generalization
?Example,Multiple Inheritance
?A class can inherit from several other classes.
Concepts of OO—Package
?What is a Package?
?A general purpose mechanism for organizing
elements into groups.
?A model element that can contain other model
elements.
?A package can be used:
?To organize the model under
development.
?As a unit of configuration
management.
Concepts of OO—Package
?A Package can contain classes
?The package,University Artifacts,contains one
package and five classes.
Differences Between OO and Structured Design
?OO
?Melds the data and data flow process together
early in the lifecycle
?Has a high level of encapsulation
?Promotes reuse of code differently
?Permits more software extensibility
Review
?What is Object Technology?
? Where is Object Technology used today?
?What is an object?
?Four principles of OO
?What is a class?
?Polymorphism and generalization
?What is Package?
走向面向对象是必然的
用较稳定把不稳定包起来
?面向对象的概念和原则
?Introduction to Object Technology
?Concepts of Object Orientation
?表示对象模型元素
?面向对象软件开发技术
?面向对象分析 (OOA)
?面向对象设计 (OOD)
?面向对象实现 (OOP)
面向对象的概念和原则
——表示对象模型元素
?Class Compartments
?The class name
?The structure (attributes)
?The behavior (operations)
Class (类 )Sh a p e
- o ri g in
- m o v e ()
+ re s iz e ()
# d is p la y ()
Name 名称
Attribute 属性
Operation 操作
Class—Name
R e ser v at i o n T i t l e
B u si n ess R u l es:,
F r au dA ge n t
O r de r
S t ock
M an ag em en t
类的名称应该:
清楚、简单,使用问题域的词汇
Class—Attributes
Class—Attributes
?UML中类属性的语法为:
[可见性 ] 属性名 [:类型 ][=初值 ]
+ public
- private
# protected
Class—Operation
?UML中类操作的语法为:
[可见性 ]操作名 [(参数列表) ] [:返回类型 ]
+ public
- private
# protected
举例:
+ display(), Area
# create()
- getLocation (Point, currentPoint)
Class
?面向对象的概念和原则
?Introduction to Object Technology
?Concepts of Object Orientation
?标识对象模型元素
?面向对象软件开发技术
?面向对象分析 (OOA)
?面向对象设计 (OOD)
?面向对象实现 (OOP)
Few things are harder to put up
with than a good example.
—— Mark Twain
An Example
定义用例 定义领域模型 定义交互图 定义设计类图
骰子游戏:
每个游戏者掷两个骰子,
总数是 7为赢,否则为输。
An Example (Cont.)
?Define Use Case 定义用例
基本路径:游戏者拿起并掷出骰子
分别得到 face value
总数为 7则赢,否则为输
游戏者 玩骰子游戏
An Example (Cont.)
?Define a Domain Model 定义领域模型
Partial domain model of the dice game
An Example (Cont.)
?Define Interaction Diagrams 定义交互图
, D i ce G a m e d i e 1, D i e d i e 2, D i e
, p l a y e r
p l a y ( )
r o l l ( )
g e t F a ce V a l u e ( )
r o l l ( )
g e t F a ce V a l u e ( )
An Example (Cont.)
?Define Design Class Diagrams 定义设计类图
?面向对象的概念和原则
?Introduction to Object Technology
?Concepts of Object Orientation
?标识对象模型元素
?面向对象软件开发技术
?面向对象分析 (OOA)
?面向对象设计 (OOD)
?面向对象实现 (OOP)
?OOA/D中最关键、最基本的能力是熟练地
为软件组织分配职责。
?OOA强调在问题领域内发现和描述对象或
概念,而不是解决方案 。 (做正确的事 )
?OOD强调的是定义软件对象和这些软件对
象如何协作来满足需求。 (正确地做事 )
OOA
Fichman & Kemerer:
我们的结论是面向对象分析方法代表了相
对过程的方法学的根本性变化,但相对于
面向数据的方法学仅仅是适当增补。面向
过程的方法学在建模过程中的关注点不是
对象的内在性质,从而导致了和面向对象
的三个基本原则(封装、对象分类和继承)
相正交的问题域模型。
OOA
?OOA 方法
?领域分析
?OO分析模型的类属成分
?OOA 过程
?对象 —关系模型
?行为 —关系模型
OOA — OOA方法
?Booch 方法
?Coad 和 Yourdon 方法
?Jocobson 方法
?Rambaugh 方法
?Wirfs-Brock方法
OOA — OOA方法
?Booch方法
?标识类和对象
?标识类和对象的语义
?标识类和对象间的关系
?进行一系列精化
?实现类和对象
OOA — OOA方法
?Coad 和 Yourdon 方法
?使用“寻找什么”( what to look for)标准来标
识对象
?定义一般 —特殊结构
?定义整体 —部分结构
?标识主题(子系统构件的表示)
?定义属性
?定义服务
OOA — OOA方法
?Jocobson 方法
?标识系统的用户和他们的整体责任
?建造需求模型
?建造分析模型
OOA — OOA方法
?Wirfs-Brock方法
?评估客户规约
?使用语法分析从规约中抽取候选类
?组合类以试图标识超类
?为每个类定义责任
?为每个类赋予责任
?标识类之间的关系
?定义类之间基于责任的协作
?构造类的层次表示以显示继承关系
?构造系统的协作图
OOA — OOA方法
?Rambaugh 方法
?开发对问题的范围陈述
?建造对象模型
?开发动态模型
?构造系统的功能模型
OOA一般步骤
?获取客户对 OO系统的需求
?使用基本的需求作为指引来选择类和对象
?为每个系统对象标识属性和操作
?定义组织类的结构和层次
?建造对象 —关系模型
?建造对象 —行为模型
?使用实例 /场景来复审 OO分析模型
OOA—领域分析
?面向对象系统的分析可以在不同的抽象层
次上进行:
?在商业或企业级
?在业务范围层次
?在应用层次
OOA—领域分析
Firesmith:
软件的领域分析是在特定应用领域中标识、
分析和规约公共需求,典型地是在应用领
域中的多个项目间的复用。面向对象领域
分析是一公共对象、类、子集合和框架等
形式在特定应用领域中标识、分析和规约
公共的可服用的能力。
OOA—领域分析
?复用和领域分析
例:对一个新应用的需求分析指明需要 100个类,两个项
目组被委派去实现该应用,各自将设计和构造一个最
终产品,每个组由具有相同的技能级别和经验的人构
成。
?组 B 将比组 A快得多地完成项目
?组 B 的产品成本将大大低于组 A的产品成本
?组 B 的产品将比组 A的产品有更少的错误
OOA—领域分析
?领域分析过程
?定义将被调查的领域
?分类将从领域中抽取出来的项分类
?收集领域中应用的代表性样本
OOA — OO分析模型的类属成分
?语义类的静态视图
?属性的静态视图
?关系的静态视图
?行为的静态视图
?通信的动态视图
?控制和时序的动态视图
OOA — OOA 过程
?OOA过程并不是从考虑对象开始,而是从
理解系统的使用方式开始
?如果系统是人机交互的,则考虑被人使用的方式
?如果系统协调和控制应用,则考虑被其他程序使
用的方式。
OOA — OOA 过程
?类 —责任 —协作者建模( CRC建模)
?定义结构和层次
?定义主体和子系统
OOA — 对象 —关系模型
?理解每个类的责任
?定义有助于完成责任的协作者,建立“连
接”
OOA — 对象 —行为模型
?评估所有的使用实例以完全地理解系统中
的交互的序列。
?标识驱动交互序列的事件,理解这些事件
如何和特定的对象相关联。
?为每一个使用实例创建事件轨迹。
?为系统建造状态 —变迁图。
?复审对象 —行为模型以验证精确性和一致
性。
OOA 小结
?面向对象分析使得软件工程师能够通过对
对象,属性和操作的表示来对问题建模, 虽然
有很多不同的方法,但所有的方法均有一个
共同的特征,
?类和类层次的表示
?对象 —关系模型的创建
?对象 —行为模型的导出
开发过程
(0)业务
(1)需求
(2)分析:结构
(3)分析:行为
(4)设计
类图的角色
OOA—— 标识对象模型的元素步骤
?标识类 /对象
?表示属性
?定义操作
OOA—— 标识对象模型的元素步骤
?标识类 /对象
?表示属性
?定义操作
识别类 (方法之一)
?回顾需求文档,抽取对应于业务实体或
事件的名词
?出现遗漏时,返回需求文档进行修改
?将名词进行分类、抽取出合适的类
例 1,SafeHome系统的过程叙述
SafeHome 软件使得房主能够在安装时
配置安全系统、监控所有和安全系统连接
的传感器、以及通过键盘及包含在
SafeHome控制面板中的功能健和房主交互。
在安装过程中,SafeHome控制面板被
用于“编程”和配置系统,每个传感器被赋
予一个编号和类型,用于启动和关闭系统
的主要码 ……
抽取其中的名词,建议一组潜在的对象
潜在对象 /类 一般分类
控制面板 外部实体
安装 发生的事情(事件)
系统 事物
主密码 事物
电话号码 事物
传感器事件 发生的事情(事件)
每个潜在对象是否应包含在分析模型中
?Coad 和 Yourdon 6个选择特征
?保留的信息
?需要的服务
?多个属性
?公共属性
?公共操作
?必要的需求
潜在对象 /类 适用的特征编号
控制面板 接受:所有均适用
安装 拒绝
系统 接受:所有均适用
主密码 拒绝,3失败
电话号码 拒绝,3失败
传感器事件 接受:所有均适用
识别类 (方法之二)
?From Use-Case Behavior
The Role of a Boundary Class
Finding Boundary Classes
?One boundary class per actor/use case pair
Boundary Class
Control Class
控制类
? 负责其它类工作
? 每个用例通常有一个控制类,控制用例中的事件顺序,控
制类也可以在多个用例间共用。
? 向其他的类发消息
The Role of a Control Class
Finding Control Classes
例:注册课程用例
OOA—— 标识对象模型的元素步骤
?标识类 /对象
?表示属性
?定义操作
识别属性
?属性是一个对象的逻辑数据值;
?一个领域模型中包含如下属性:
?需求建议
?暗示我们需要记住的那些信息
例如:收据经常包含一个日期和时间;因为由于各种原
因,管理层需要知道销售的日期和时间。 因此,
撒了需要一个 date和 time属性。
识别属性
?有效的属性类型
?保持属性的简单性
?概念角度和实现角度
?非原始的数据类型类
?可以分开的段组成的数据(电话号码)
?与数据相关(身份证号)
?包含其他属性的数据(促销价格可能有一个日期)
?带有单位的数量值(货币)
?没有属性是外健
区别正确和不正确的属性
? 是否在系统责任之内
? 是否描述类对象的特征
? 是否存在冗余
? 是否有复杂结构的属性
? 根据对需求的理解进行细化
OOA—— 标识对象模型的元素步骤
?标识类 /对象
?表示属性
?定义操作
定义操作
用例文档 类图
通过画顺序图完成责任分配
检索零件
基本路径
1,检索零件者提交查询条件
2,系统按查询条件检索零件
3,系统显示搜索到零件的列表
4,检索零件者选中某个零件
5,系统显示该零件的详细信息
扩展
2a,系统没有检索到所需零件:
2a1,系统显示, 没有找到适合条件的零件,
2a2,用例结束
会员
检索零件
检索零件类图
检索零件 UI
( f r o m L o g i c a l V i e w )
< < b o u n d a r y > >
检索零件 UC
( f r o m L o g i c a l V i e w )
< < c o n t r o l> >
零件
( f r o m L o g i c a l V i e w )
< < e n t i t y > >
顺序图解说
:会员
, 检索零件 UI, 检索零件 UC, 零件
, 会员
1, 提交查询条件
2, 检索零件()
3, 检索零件()
4, 显示零件列表()
5, 选中零件()
6, 取零件信息()
7, 取零件信息()
8, 显示零件详细信息()
面向对象软件开发技术
?面向对象分析 (OOA)
?面向对象设计 (OOD)
?面向对象实现 (OOP)
OOD
?将 OOA所创建的分析模型转变为将作为软
件构造的蓝图的设计模型。
?完成一系列不同的模块性等级的设计。
?主要的系统构件 —子系统的系统级模块
?数据和操纵数据的操作被封装为对象 —构造块的模块
形式
?属性的特定数据组织和个体操作过程细节 —数据和算

?Gamma:
设计面向对象的软件是困难的,设计可服
用的面向对象的软件更加困难。你必须找
到适当的对象、以适当的粒度将它们转化
为类的因子、定义类接口和继承层次以及
建立他们之间的关键关系。
OOD— OO系统的设计
子系统设计
类及对象设计
消息设计
责任设计
OOD设计金字塔
OOD — OO系统的设计
?设计问题
?判断设计方法的模块化的能力
?分解性 (decomposability)
?组装性 (composability)
?易理解性 (understandability)
?连贯性 (continuity)
?保护性 (protection)
?设计原则
?语义模块单元
?很少的接口
?小的接口
?显示的接口
?信息隐蔽
OOD — OO系统的设计
?流行方法
?Booch方法
?Coad和 Yourdon方法
?Jacobson方法
?Rambaugh方法
?Wirfs-Brock方法
OOD — OO系统的设计
?一般过程
?以可实现的方式描述每个子系统
?对象设计
?消息设计
?复审设计模型并在需要时迭代
OOD— OO设计模型的类属成分
分析
系统设计
对象设计
OOD— 系统设计过程
?划分分析模型
?并发性和子系统分配
?任务管理构件
?数据管理构件
?资源管理构件
?人机界面构件
?子系统间通信
OOD— 对象设计过程
?对象描述
?涉及算法和数据结构
?程序构件和接口
OOD— 设计模式
?描述设计模式
?在设计中使用设计模式
OOD小结
?OOD 将现实世界的 OOA模型转换为可以用
软件实现的实现 —特定的模型,OOD 过程可
以描述为有四个坚持层次的金字塔,
?OOD有很多方法,虽然各自互补相同,但均
遵从设计金字塔,通过两个层次的抽象完成
设计过程 —系统和子系统的设计遗迹个体
对象的设计,
?子系统设计涉及四类构件,问题域构件,人机
交互构件,任务管理构件,数据管理构件,
OOD 代表了一种独特的软件工程方法,
Tom Love
软件问题的根可能在于我们的产业 —数据
处理的描述中最传统的术语,我们被告知
数据和数据处理是构成我们的业务基础的
两不同的“事物”, 该划分所带来的危害可
能远比我们认识到的多得多,
面向对象软件开发技术
?面向对象分析 (OOA)
?面向对象设计 (OOD)
?面向对象实现 (OOP)
面向对象实现 (OOP)
?实现语言
?基本实现手段
?实现环境
?编码调试
?测试
基本实现手段
?类定义
?对象创建
?结构定义
?实例关联定义
?操作调用和消息发送
?内存管理
?封装
?多态
实现环境
?类库
?开发工具
编码调试
?编码
?代码调试
测试
?应用系统测试
?类测试
RUP 部分工件及其时间安排
流程 工件 初始 精化 构造 移交
业务建模 领域模型 s
需求 用例模型 s r
构想 s r
补充规范 s r
术语表 s r
设计 设计模型 s r
软件架构文档 s
数据模型 s r
实现 实现模型 s r r
项目管理 软件开发计划 s r r r
测试 测试模型 s r
环境 开发案例 s r
阅读:
?软件工程 —实践者的研究方法 ( Software
Engineering-A Practitioner’s Approach)
Chapter 19~23