Objected-Oriented Analysis and Design-3

本文为华东师范大学开设的面向对象分析与设计慕课课程第三周笔记,主要介绍了面向对象分析法的名词法与分析模型法,同时举了一些例子(本文略)来更好理解整个分析到设计的过程。

Overview of Object-Oriented analysis and design

良好的对象设计意味着什么?

是构建高质量软件系统的基本要求,如

  • Architectural cohesion 架构性的内聚
  • Reusability 可重用性
  • Maintenance 可维护性
  • Scalability 可扩展性
  • Flexibility 灵活性
为软件对象分配指责
  • A critical ability in OO development is to skillfully assign responsibilities to software objects.
    • Responsibility-driven design 职责驱动的设计
    • Performed during Design workflow 在设计的过程中完成职责分配
    • Follows GRASP principles 遵循GRASP原则
      • General Responsibility Assignment Software Pattern 通用职责分配软件模式
    • Successful designs become Patterns 成功的设计可以成为模式
What is Analysis 什么是分析

Analysis is investigation of the problem and requirements, rather than a
solution. 面对你所要解决的问题领域,搞清楚问题是什么,而不考虑怎么解决

What is Design 什么是设计

Design is a conceptual solution that fulfills the requirements. 概念性的、满足需求的解决方案

分析与设计的关系:do the right thing (analysis), and do the thing right (design) 做正确的事情 (分析) ,正确地做事情 (设计)

What is Implement 什么是实现

Implementation is expression of the design in code.

What is Deployment 什么是部署

Deployment is the actual installation in the host environment.

What is OOA 什么是面向对象分析

finding and describing the objects or concepts in the problem domain 发现并描述问题领域里的对象或者概念 (概念类)

What is OOD 面向对象设计?

defining software objects and how they collaborate to fulfill the requirements 定义软件对象、以及它们之间如何协作完成功能的 (设计类)

For example, Airplane example of object and class discovery

  • OOA: in the case of the flight information system, some of the concepts include: Plane, Flight, and Pilot.
  • OOD: a Plane software object may have a tailNumber attribute and a getFlightHistory() method
  • then, implement

OOAD Simple Example OOAD的基本过程

以一个普通的扔骰子的游戏为例,游戏规则如下,玩家先后扔2个骰子,若两个骰子的点数和大于7则为胜利,反之为失败。

  • 定义用例
  • 定义领域模型 (domain model)

    • domain model: a visual representation of conceptual classed or real-situation objects in a domain. 问题领域的概念类以及真实对象的可视化表示

    • 在这个例子中,领域模型为: Player, Dice, DiceGame

      领域模型图本质上是没有方法的类图

  • 定义交互图

    • Assignment of responsibilities among objects
  • 定义设计类图

    • Software classes with methods according to responsibilities and attributes according to visibility

LRG: lower representational gap 低表示差异

  • 领域模型和设计类图有很大的相似之处,在领域模型中找到的概念类在设计的时候可以直接拿来用
  • 分析的结果是设计的输入

面向对象分析法

在软件工程,分析是一种过程,把用户需求转变为系统需求

大的、复杂系统的开发,有两种主要的分析方法

  • Function-oriented analysis 面向功能的分析
    • concentrating on the decomposition of complex functions to simply ones.
  • Object-oriented analysis 面向对象分析
    • identifying objects and the relationship between objects.
  • 在抽象层面,面向功能的分析法用得多一点
  • 在模块层面,面向对象分析法用得多一点
面向对象分析主要步骤
  • Identifying objects 识别对象
  • Organizing the objects 组织对象
    • classifying the objects identified, so similar objects can later be defined in the
      same class.
  • Identifying relationships between objects 定义对象之间的关系
    • this helps to determine inputs and outputs of an object.
  • Defining operations of the objects 定义对象的操作
    • the way of processing data within an object. (Also known as ‘responsibility assignment’)
  • Defining objects internally 定义对象内部细节

    Three ways to do Object Oriented Analysis 如何寻找概念类
  • Conceptual model (Larman) 概念模型,又称”名词法”

  • Analysis model with stereotypes (Jacobson) 分析模型法
    • 从Boundaries, entities, control 三方面来寻找
  • CRC cards (Beck, Cunningham) CRC (Class Responsibility Cooperation) 法
名词法定义概念类
  • 重用或者修改已有的模型 Reuse or modify existing models.
    • This is the first, best, and usually easiest approach
  • 借助行业、公司内部法的“概念类列表 ” Concept Category List
  • 在需求描述中查寻名词 (短语) Finding Concepts with Noun Phrase Identification.

A central distinction between object oriented and structures analysis:

  • 前者根据对象划分系统,而后者根据功能 division by concepts (objects) rather than division by functions.
分析模型法 Analysis model with stereotypes(构造型)
  • 用于描述系统规格说明
  • 一个健壮、稳定的模型,必须与实现环境无关
  • 实现环境的任何变化,不会影响到系统的逻辑结构
  • 分析模型能够关注到系统的信息、行为、展示(输入/出)等特性
  • 表示符号

The model is defined in information - behaviour - presentation space.

上述提到的Entity, Boundary/Interface, Control 在空间的位置如下图:

  • Presentation 相当于一个展示的窗口,和外面的事物打交道 (接口)

面向对象设计(初步)

一般原则
  • An object-oriented system is composed of objects sending messages to other objects
  • The quality of the overall design depends on which object is doing what
    • 比喻:“人尽其责、各有所长”
  • That is, the quality depends on how we assign responsibilities to the objects
职责驱动的设计 (RDD Responsibility Driven Design)
  • Think of objects in terms of what they do or know (the human worker metaphor!) 设计时考虑对象做什么、或者知道什么

  • An object’s obligation or contract that it offers to other objects 一个对象对其他对象承担的义务或者合约

  • A responsibility is really a behavior the other classes depend on 职责是一个对象的行为,而其他的对象依赖这种行为

以职责为角度,提取对象的操作,属性

职责的定义
  • 认知职责 Knowing
    • about private encapsulated data
    • about related objects
    • about things it can derive or calculate
  • 行为职责 Doing
    • doing something itself
    • initiating action in other objects
    • controlling and coordinating activities in other objects
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×