软件设计 day1
阅读原文时间:2023年07月08日阅读:1

Software Design Methodology 软件设计方法学

中国石油大学(华东)2022-2023-3 国际周课程 Advanced software design

张晓东老师邀请在日本广岛大学工作的刘少英老师(华裔)进行授课

刘少英老师的介绍:

Shaoying Liu (劉少英)

Graduate School of Advanced Science and Engineering & School of Informatics and Data Science

高等科学与工程&信息学与数据科学学院研究生院

Hiroshima University, Japan 日本广岛大学

Email: sliu@hiroshima-u.ac.jp 邮箱

HP: https://home.hiroshima-u.ac.jp/sliu/ 个人网页

注:ppt为英文,这是百度翻译+我自己粗翻的,可能有的地方不到位,外加一些老师讲的内容

The Goal of This Course 这门课程的目标

  • Basic concepts of software design

    软件设计的基本概念

  • Software design process

    软件设计过程

  • Software design principles

    软件设计原则

  • Software design methods

    软件设计方法

  • Software design representations

    软件设计表示

  • Implementation based on software design

    基于软件设计的实现

How to Effectively Learn This Course 如何高效的学习这门课

  • Attending classes

    参与课程

  • Actively working on class exercises and discussions

    积极参与课堂练习和讨论

  • Trying to complete homework

    努力完成课后作业

Reference Books 参考书

  • “Software Design”, by David Budgen, Addison-Wesley, 1994. ISBN: 0-201-54403-2.

    似乎没有中文翻译版 https://dl.acm.org/doi/book/10.5555/561889

  • “Fundamentals of Object-Oriented Design in UML”, by Larry L. Constantine, Dorset House Publishing and Addison-Wesley, 2000. ISBN: 0-201-69946.

    《UML面向对象设计基础》

  • “Formal Engineering for Industrial Software Development”, by Shaoying Liu, Springer-Verlag, ISBN: 2004, ISBN 3-540-20602-7.

    这个是老师自己的专著

  • “GUI Bloopers – Common User Interface Design don’ts and Dos”, by Jeff Johnson, Morgan Kaufmann Publishers, 2008

    《GUI设计禁忌》

Main Contents of This Course 课程主要内容

  • Part I: Introduction to Software Design

    第一部分:软件设计导论

  • Part II: Structured Design and Design Representations

    第二部分:结构化设计与设计表示

  • Part III: Object-Oriented Design and UML

    (Unified Modeling Language)

    第三部分:面向对象设计与统一建模语言

  • Part IV: Graphical User Interface (GUI) Design

    第四部分:图形用户界面设计

Part I: Introduction to Software Design 第一部分:软件设计导论

  • What is design?

    什么是设计?

  • What is software?

    什么是软件?

  • What is software design?

    什么是软件设计?

  • Software design principles

    软件设计原则

  • Software design methods

    软件设计方法

Design is an activity or process of making a plan or a model for a potential product. It usually involves problem-solving and decision-making to address specific needs for software qualities.

设计是为潜在产品制定计划或模型的活动或过程。它通常涉及解决问题和决策,以满足软件质量的特定需求。

Example举例

Steps for design: 设计步骤:

Requirement: 需求:

Build a house with the following parts:

用以下部分建造房屋:

two sides

两侧面

one end

一后

one door

一扇门

two roof panels

两片屋顶顶盖

one front

一前

The role of the design: 设计的作用:

(1)The design allows the user and the developer evaluate the functionality, shape, properties, and usability of the product before it is actually made.

(1)设计允许用户和开发人员评估产品在实际被制作出来之前的功能、形状、特性,以及可用性。

(2)The design provides a foundation for producing the planned product.

(2)设计为生产理想中的产品奠定了基础。

Software refers to data and programs in general, but in Software Engineering, software often refers to documentation, data and programs.

软件通常指数据和程序,但在软件工程中,软件通常指文档、数据和程序。

程序是按事先设计的功能和性能要求执行的指令序列。

数据是使程序能正常操纵信息的数据结构。

文档是与程序开发,维护和使用有关的图文材料。

Software = Data + Programs

软件=数据+程序

What is a program? 什么是程序

A program is a combination of data structure and algorithm expressed in a specific programming language.

程序是用特定编程语言表达的数据结构和算法的组合。

Program = Data structure + Algorithm

程序 =数据结构 + 算法

What is an algorithm? 什么是算法

An algorithm is a sequence of instructions, commands, or actions. It can be expressed using graphical languages, natural languages, and programming languages.

算法是一系列指令、命令或动作。它可以使用图形语言、自然语言和编程语言来表达。

Examples of algorithm and program: 算法和程序的例子

algorithm example

An algorithm for calculating the average of students’ exam scores:一种计算学生考试成绩平均值的算法:

  • (1) Input all students’ scores

    输入所有学生的分数

  • (2) Calculate the total score of the students

    计算学生们的总分

  • (3) Divide the total score by the number of the students to get the average score

    将总分除以学生人数得出平均分

  • (4) Print out the average score

    打印出平均分数

Java-Pseudocode for calculating the average score:

用于计算平均分数的Java伪代码:

int score = 0; stuNum = 0; totalScore = 0;
double averageScore = 0;
int controlVar = 0;
//variables showing data structures 显示数据结构的变量
for (int count = 0; controlVar = 0; count++)
{
score = read a score; //pseudocode for reading a score 读取分数的伪代码
 if (score >= 0) {
stuNum = stuNum + 1;
totalScore = totalScore + score;
}
else //if a negative value is read for score, the loop will terminate  如果读到一个负数分数,循环将终止
controlVar = 1; //for terminating the for loop 停止循环
avergeScore = totalScore / stuNum;
System.out.println(“The average score is:” + averageScore);
Program example

数据结构

class ExamRecord {
String name;
int math;
int japanese;
int english;
}

函数

public class ExamRecordAction {
public static void main(String[] args) {
ExamRecord p = createExamRecord("Taro", 50, 90, 100);
showExamRecord(p);
}
public static ExamRecord createExamRecord(
String name, int math, int japanese, int english){
ExamRecord r = new ExamRecord();
r.name = name;
r.math = math;
r.japanese = japanese;
r.english = english;
return r;
}
public static void showExamRecord(ExamRecord r){
System.out.println(r.name + ", 数学 = " + r.math
+ ", 国語 = " + r.japanese
+ ", 英語 = " + r.english
+ ", 3科目の平均 = "
+ ((r.math + r.japanese + r.english) / 3.0));
}
}

Elements contained in the program 程序中包含的元素

  • Data-related elements:class and variable

    数据相关元素:类和变量

  • declarations

    声明

  • Operation-related elements:method name,

    与操作相关的元素:方法名,

  • parameters, and return type

    参数和返回类型

  • The types of variables

    变量的类型

  • The method body

    方法体

  • Statements used in the method body

    方法体中使用的语句

  • Method invocation (like function call)

    方法调用(类似于函数调用)

  • Relation between classes

    类之间的关系

Questions

  • How is the program structure determined?
  • How are the elements of the program created?
  • How are the relations between various program elements decided?

Answer: Software Design

A program can be regarded as a function in mathematics.

在数学中,一个程序可以看作是一个函数。

P: D → R

Program: Domain → Range

where P is a function from D to R,D is the domain of function P, and R is the range of P.
其中P是从D到R的函数,D是函数P的定义域,R是P的值域。

The goal of software design is to determine the two things:

软件设计的目标是决定两件事:

(1)The domain D and the range R of P.

函数P的定义域D和值域R

(2)The definition of P.

函数P的定义

Example, P(x) = |x|, a program obtaining the absolute value |x| for an input real number x.

例如,P(x)=|x|,一个获得输入实数x的绝对值|x|的程序。

Software design is a process and activity of making a plan or creating a model for the expected software system.

软件设计是为预期的软件系统制定计划或创建模型的过程和活动。

Questions:

问题:

  • (1)How to create a plan or model?

    如何创建计划或模型?

  • (2)How to represent the plan or model?

    如何表示计划或模型?

  • (3)How can the model be used for coding?

    如何将模型用于编码?

When to carry out software design? 何时进行软件设计?

Abstract design 抽象设计

Abstract design: focusing on the following issues:

抽象设计:主要关注以下几个问题:

  • Propose the architecture of the software

    提出软件架构

  • Determine the operations and the related input and output data items

    确定运算以及相关的输入和输出数据项

  • Determine the way operations interact with each other

    确定运算之间的交互方式 比如:调用数据流

Important point:

要点:

The above software elements are abstractly represented in abstract design.

上述软件元素在抽象设计中被抽象地表示。

Detailed design详细设计

Detailed design: focusing on the following issues:

详细设计:主要关注以下几个问题:

  • Decide appropriate data structures for data items (by means of using appropriate data types to declare variables)

    为数据项确定适当的数据结构(通过使用适当的数据类型来声明变量)

  • Create algorithms for implementing operations

    制作用于实现运算的算法 用自然语言、图形语言等都可以

  • Propose a Graphical User Interface (GUI)

    设计图形用户界面

Important point:

要点:

The above software elements are represented in detail in detailed design

上述软件元素在详细设计中被详细地表示。

The characteristics of software design 软件设计的特点

  • There is no mathematical formula for software design.

    软件设计没有数学公式。 是因为要求设计师都拥有极高的数学素养不现实吗?

  • We do not say whether a program design is true or false but can say a program is better than another one in terms of some software qualities.

    我们不能说程序设计是真是假,但可以说一个程序在某些软件质量方面比另一个程序更好。

  • Program design is an intellectual, creative, and rigorous activity.

    程序设计是一项智力的、创造性的和严谨的活动。

As a product, software has many qualities, including

作为一种产品,软件具有许多质量特性,包括

  • Reliability 可靠性
  • Correctness 正确性
  • Efficiency 效率
  • Usability 可用性
  • Maintainability (readability, simplicity) 可维护性(可读性,简易性)
  • Reusability 可复用性
  • Robustness 稳健性
  • Portability 可移植性

功能性指所实现的功能达到它的设计规范和满足用户需求的程度;可靠性指在规定的时间和条件下,软件能够正常维持其工作的能力;可使用性指为了使用该软件所需要的能力;效率指在规定的条件下用软件实现某种功能所需要的计算机资源的有效性;可维护性指当环境改变或软件运行发生故障时,使其恢复正常运行所做努力的程度;可移植性指软件从某一环境转移到另一环境时所做努力的程度。

Reliability ー concerned with continuous 可靠性 ー 与可持续有关

providing expected services. It is the probability of not encountering errors during the program execution within a certain period of time.

提供预期服务。它是指在一定时间段内程序执行过程中不遇到错误的概率。

在规定的时间和条件下,软件能够正常维持其工作的能力

General interpretation 一般性解释

Example:例子

  • (1)Reliable person 可靠的人

All promises are implemented, or at least sufficient efforts are made to try to implement all his promises

所有的承诺都得到了履行,或者至少做出了足够的努力来努力履行他的所有承诺

老师举例子举了川普,我确实万万没想到,这是文化环境差异嘛

*(2)Reliable airplane 可靠的航班

① Always fly in the way as designed.

始终按既定航道飞行。

② Guarantee the safety of the airplane and passengers

保证飞机和乘客的安全

*(3)Reliable sausage machine 可靠的香肠机

要求:给定一只小猪作为输入,香肠机总是生产香肠。

  • Unreliable sausage machine: 不可靠的香肠机

  • Another example: 其他例子

P(x) = |x|, a program obtaining the absolute value of a given real number x.

P(x)=|x|,一个获得给定实数x的绝对值的程序。

不可靠的程序

Correctness

If a program implements exactly the desired functions defined in the specification, the program is said to be correct with respect to the specification.

如果一个程序准确实现了规约中被定义的所需功能,则该程序正确符合规约。

后面这句不太会翻译

Example: 例子:

  • Specification: for any input real number x, the output of program P must be the absolute value of x.

    规约:对于任何输入的实数x,程序P的输出必须是x的绝对值

  • Program: the algorithm of P is written in such a way that always obtains the absolute value of the input real number x.

    程序:P的算法是以这样一种方式编写的,即总是获得输入实数x的绝对值。

Question: How to prove program P is correct with respect to its specification? Testing? Formal proof?

问题:如何证明程序P正确符合其规约?测试?形式证明?

Relationship between Correctness and Reliability 正确性和可靠性的关系

  • Relationship: Correctness helps improve the software reliability but does not necessarily guarantee the 100% reliability.

    关系:正确性有助于提高软件的可靠性,但不一定能保证100%的可靠性。

  • Reason: the specification may not be guaranteed to accurately reflect the user’s requirements.

    原因:规约可能无法保证准确反映用户的要求。

The gap between specification and the user’s requirements 规约与用户需求之间的差距

Verification is a means to ensure that the program satisfies the specification.

验证(Verification)是确保程序符合规约的一种手段。

Validation is a means to ensure that the program satisfies the requirements of the user.

核实(Validation)是确保程序满足用户需求的一种手段。

Efficiency 效率

—— concerned with program execution speed and the amount of memory used within a unit time.

—— 与程序执行速度和单位时间内使用的内存量有关

In general, the faster the program execution speed is, the more efficient the program will become.

一般来说,程序执行速度越快,程序的效率就越高

However, one of the most important techniques to improve program execution speed is to use more memory spaces.

然而,提高程序执行速度的最重要的技术之一是使用更多的内存空间。

Importance: a good balance between speed and memory usage should be achieved.

重点:应该在运行速度和内存使用之间取得良好的平衡。

Usability 可用性

ー is a measure how easily a program can be used in its operation by users.

—— 是衡量用户操作使用程序的容易程度的指标

用户使用软件时是否感觉方便。

以用户为中心进行设计:功能丰富,用户操作方便

Challenge: There is no universally agreed method for defining the usability. Usability is a rather subjective concept and its decision should be dependent on specific users.

挑战:对于可用性的定义,目前还没有达成一致的方法。可用性是一个相当主观的概念,它的决定应该取决于特定的用户。

Maintainability 可维护性

ー is a measure how a program can be easily evolved or changed for improvement.

是一种衡量程序如何容易地扩展或修改以进行改进的方法。

Factors to affect maintainability:

影响可维护性的因素:

(1) readability: if a program is readable, it will be easily understood by the programmer or other developers. This will help the programmer change the program correctly.

可读性:如果一个程序是可读的,那么它将很容易被程序员或其他开发人员理解。这将帮助程序员正确地更改程序。

(2) simplicity: If a program is logically simple, it will help the programmer easily understand the program and therefore easily carry out the necessary changes in the program.

简单性:如果一个程序在逻辑上很简单,它将帮助程序员轻松地理解程序,从而轻松地对程序进行必要的更改。

Reusability 可复用性

ー is a measure how a program or its parts can be easily reused in another program under development.

是衡量一个程序或它的一部分在另一个被开发的程序中轻松复用的一个指标

Factors to contribute to the reusability:

有助于可复用性的因素:

(1) modularity: a quality of a program consisting of separated parts that, when combined, form a complete whole.

模块化:是程序由分离的部分组成,当这些部分组合在一起时,形成一个完整的整体的一种质量特性

(2) testability: a quality of a program that can be easily tested to evaluate its functional performance and confirm the necessary constraints.

可测试性/易测性:是程序可以很容易地进行测试,以评估其功能表现并确认必要约束条件的一种质量特性

Robustness 稳健性

ー is a measure whether a program can gracefully manage the normal and abnormal situations, such as normal executions and executions encountering exceptions.

ー 是衡量程序是否能够优雅地处理正常和异常情况,例如正常情况下的执行操作和遇到异常情况的执行操作。

By gracefully managing the situations we mean that without causing the program crash, unexpected termination, or unexpected nontermination, the situation can be managed properly.

通过优雅地处理这些情况,我们的意思是,在不导致程序崩溃、意外终止或意外未终止的情况下,情况可以被正确处理。

系统或算法在面对不确定性或异常情况下保持稳定的能力

Portability 可移植性

ー is a measure of whether software can be ported without requiring major rework.

—— 是衡量软件是否可以在不需要大量返工的情况下跨平台的指标。

Porting is the task of doing any work necessary to make the computer program run in the new environment.

移植是指完成任何必要工作使计算机程序在新环境中运行。

Example: a portable application program could work on platforms such as Windows, Linux, iOS and Android without a need to be changed in its code. The porting process might include transferring installed program files to another system or creating the same program using different source code.

示例:移动式应用程序可以在Windows、Linux、iOS和Android等平台上运行,而无需更改其代码。移植过程可能包括将安装的程序文件传输到另一个系统,或者使用不同的源代码创建相同的程序

软件是否可以在不同的平台上运行,而不需要大量的修改和适配

Classification of software qualities 软件质量特性的分类

  • The qualities that interest the user:Reliability, Correctness, Efficiency, Usability, and Robustness.

    用户关心的:可靠性,正确性,效率,可用性,稳健性

  • The qualities that interest the developer:maintainability, reusability, and portability.

    开发者关心的:可维护性,可复用性,可移植性

How to ensure program qualities? 如何确保软件质量

  • Using effective principles to design software

    使用有效的原理来进行软件设计

  • Using effective design methods to design software

    使用有效的设计方法来进行软件设计

  • Using comprehensible languages to represent software designs

    使用可理解的语言表示软件设计

Abstraction and Decomposition 抽象和分解

  • Abstraction is a technique, process, or activity to obtain the most important information from a document or information by removing properly unnecessary details.

    抽象是一种通过适当地删除不必要的细节,从文档或资料中获得最重要的信息的技术、过程或活动。

  • Decomposition is a technique, process, or activity to break down a large task or an abstract expression into into smaller tasks or concrete expressions.

    分解是一种将大型任务或抽象表达分解为较小任务或具体表达的技术、过程或活动。

for exmaple:explaining Hosei University

举例子:介绍日本法政大学

Abstraction:Hosei University is a prestigious privateuniversity in Japan with three campus:

抽象:日本法政大学是日本著名的私立大学,有三个校区:

• Ichigaya campus

• Koganei campus

• Tama campus

校区名字估计是音译的,就不翻译了

Decomposition:

分解:

(1)Ichigaya campus has: 第一个校区拥有:

Faculty of Law, Faculty of Letters, 文法学院

Faculty of Business administration, 工商管理学院

Faculty of International Communication, 国际文化学院

Faculty of Sustainability Studies, 可持续发展研究学院

Faculty of Lifelong Learning and Career Studies, 生涯设计学院

Faculty of Engineering Design 设计工学院

(2) Koganei campus has: 第二个校区拥有:

Faculty of Science and Engineering, 理工学院

Faculty of Computer and Information Science, 信息科学院

Faculty of Bioscience and Chemistry 生命科学院

(3) Tama campus has: 第三个校区拥有:

Faculty of Economics, 经济学院

Faculty of Social Sciences, 社会学院

Faculty of Social Policy and Administration, 现代福祉学院

Faculty of Sports and Health Studies 体育健康学院

Encapsulation and Information Hiding 封装和信息隐藏

Encapsulation is one of the fundamental concepts in object-oriented programming (OOP). It means that the related data and operations are organized or defined in a program unit (e.g., class).

封装是面向对象编程(OOP)的基本概念之一。它意味着相关的数据和操作是在程序单元(例如类)中组织或定义的。

Information hiding refers to the fact that the implementation details of both data and operations in the program unit are not exposed to outside the unit. Only necessary interface is provided to the outside for using the operations provided by the unit.

信息隐藏是指程序单元中的数据和操作的实现细节不暴露在单元外部。仅向外部提供必要的接口,以便使用单元提供的操作。

Encapsulation is a means to realize information hiding.

封装是实现信息隐藏的一种手段。

Information hiding is an effect of encapsulation.

信息隐藏是一种封装的效果。

Example: 例子:

Stack is a data structure following the LIFO (Last-in-First-Out) principle.

堆栈是遵循后进先出原则的数据结构。

Interface:

Initialize()
Push()
Pop()


class Stack {
private int[] a = new int[10];
private int top = 0;
public void Initialize() {…};
public void Push(){…};
public int Pop(){…};
private Is-Full(){…}; //Does the stack have 10 elements? 栈满?
private Is-Empty(){…};//Does the stack contain no element? 栈空?
}

Question ? 问题

Why do we need information hiding in programming?

为什么我们要将信息隐藏在程序中?

信息隐藏的目的在于保证隐藏数据不被未授权的第三方探知和侵犯,保证隐藏的信息在经历各种环境变故和操作之后不受破坏

Modularization 模块化

Modularization is the process of separating the functionality of a program into independent, interchangeable modules, such that each contains everything necessary to execute only one aspect of the desired functionality

模块化是将程序的功能分离为独立的、相互联系的模块的过程,这样每个模块都包含执行所需功能唯一方面所需的一切

Examples: 例子:

Computer (CPU, Input unit, Output unit, Memory unit)

计算机(中央处理器、输入单元、输出单元、存储单元)

Automobile (Engine, Battery, Alternator, Radiator, Steering, Breaks)

汽车(发动机、蓄电池、交流发电机、散热器、方向盘、制动器)

Japanese bento (lunch box) (rice, meat, vegetables, fish, sweet)

日本便当(午餐盒)(米饭、肉、蔬菜、鱼、甜食)

_**How to realize the above design principles? 如何实现上述的设计原理

We need effective design methods!我们需要有效的设计方法**_

Class exercise 1 课堂练习1

Take the automobile as an example to explain the following concepts:

以汽车为例,解释以下概念:

• Reliability(可靠性)

• Efficiency(效率)

• Usability(可用性)

• Maintainability(可维护性)

• Reusability(可复用性)

• Robustness(稳健性)

  • Top-down design 自顶向下设计
  • Bottom-up design 自底向上设计
  • Modular design 模块化设计
  • Structured design 结构化设计
  • Object-oriented design 面向对象设计
  • Component-based design 基于组件的设计

I.6.1 Top-down design 自顶向下设计

Top-down design supports the abstraction and decomposition design principle.

自上而下的设计支持抽象和分解的设计原则。

Specifically, using top-down design, the potential system to be implemented is first abstracted into a high-level operation. Then, the high-level operation will be properly decomposed into smaller operations each of which focuses on a specific task.

具体来说,使用自上而下的设计,首先将要实现的潜在系统抽象为高级运算。然后,高级运算将被适当地分解为较小的运算,每个运算都专注于一个特定的任务。

Example: Design of a University Information System.

示例:大学信息系统的设计。

  • (1) Abstraction: the top-level operation of the system:

    抽象:系统的顶层运算:

  • (2) Decomposition:

    分解:

  • (3) Decomposition:

    分解:

  • (4) Decomposition:

    分解:

I.6.2. Bottom-up design 自底向上设计

Bottom-up design is the opposite to top-down design, with the following guidelines:

自下而上的设计与自上而下的设计相反,遵循以下指导原则:

(1) First, the low-level operations are designed.

首先,设计底层运算。

(2) The designed low-level operations are used to construct high level operations.

设计好的低级运算用于构造高级运算。

(3) The designed high-level operations are used to build higher level operations.

设计好的高级运算用于构建更高级别的运算。

Example: Bottom-up design of a University Information System

示例:大学信息系统的自底向上设计。

  • (1) Bottom-level operations are first designed. 先设计底层运算。

The other bottom-level operations:其他的底层运算:

  • (2) Use bottom-level operations to construct high-level operations.

    使用底层运算用于构造高级运算。

  • (3) The top-level operation is finally constructed. 最终构建了顶层运算。

Comparison between top-down design and bottom-up design:自顶向下设计与自底向上设计的比较:

  • Top-down design is a process of from abstraction to detailed representation.

    自顶向下设计是一个从抽象到详细表达的过程。

  • Bottom-up design is a process of from detailed representation to abstraction by composing low-level operations to build high-level operations.

    自底向上设计是一个从详细表达到抽象的过程,通过编写低级运算来构建高级运算

  • Top-down design is effective for designing a system in an unfamiliar application domain, while bottom-up design is effective for designing a system in a familiar application domain.

    自顶向下设计对于在不熟悉的应用领域中设计系统更有效,而自底向上设计对于在熟悉的应用域中设计系统更有效。

  • Top-down design starts from the goal of the design and develops the details necessary to realize the goal, therefore, allowing the designer to have a comprehensive view of the whole system under design. In contrast, bottom-up design may not allow the designer to have a comprehensive view of the whole system from the beginning, therefore, facing a higher risk of making a bad design.

    自顶向下设计从设计的目标着眼,并开发实现目标所需的细节,因此,使设计师能够全面了解设计中的整个系统。相比之下,自底向上设计可能不允许设计者从一开始就对整个系统有一个全面的看法,因此,拥有更高概率会做出糟糕设计。自顶向下更有全局观,自底向上可能出现对接失败,做的东西和目标不一致的现象

  • In general, a middle-out design that combines top-down and bottom-up design is used. It allows the designer to start from designing middle level operations and then take top-down and bottom-up approaches to finish the design of the whole system.

    一般来说,使用自顶向下和自底向上相结合的中间向外设计。它允许设计者从设计中层操作开始,然后采取自顶向下和自底向上的方法来完成整个系统的设计。

I.6.3 Modular design 模块化设计

Module design refers to the way of designing a software system as inter-related modules each of which focuses on an independent task or function.

模块设计是指将软件系统设计为相互关联的模块,每个模块都专注于一个独立的任务或功能。

What is a module? A module is an independent program unit that realizes one function of the whole system.

什么是模块?模块是实现整个系统的一个功能的独立程序单元。

接下来这处的翻译我搞不太明白,大概意思是 module 的两层含义。第二层含义看着和面向对象有点像

Levels of module:

模块级别:

  • (1) operation level (e.g., function in C, method of a class in Java)

    操作级别(例如,C中的函数、Java中的类的方法)

  • (2) group level (e.g., class in Java)

    组级别(例如Java中的类)

Characteristics of a module:模块的特点:

  • A module has a normal size (not too big and not toosmall)

    模块具有正常大小(不太大也不太小)适中

  • A module fulfills an independent task or function.

    模块完成独立的任务或功能。

  • A module encapsulates data and algorithm.

    模块封装数据和算法。

  • A module hides the implementation details from the outside environment.

    模块对外部环境隐藏实现细节。

  • A module can be easily replaced by another module using different data or algorithm to fulfill the same function.一个模块可以很容易地被另一个模块取代,该模块使用不同的数据或算法来实现相同的功能。

Example: when designing the University Information System, we can design a module for each of the functions: Course management, Research management, Lecture management, Examination management, Study records management etc.

例如:在设计大学信息系统时,我们可以为每个功能设计一个模块:课程管理、研究管理、讲座管理、考试管理、学习记录管理等。

I.6.4 Structured design 结构化设计

Structured design comes from structured programming that advocates the use of only three program constructs, which are sequence, choice(or selection), and iteration, to construct programs with single-entry and single-exit.

结构化设计源于结构化编程,它提倡只使用序列、选择和迭代三种程序结构来构建具有单入口和单出口的程序。

A structured program does NOT use "go to" command or statement.

结构化程序不使用“go to”命令或语句。

Program constructs with single-entry and single exit:

具有单入口和单出口程序结构: program constructs应该是个名词

S1; S2
if C then S1 else S2 (or if (C) S1 else S2)
while C do S (or while (C) S)

The flowchart of these three constructs are given next.

下面给出这三个结构的流程图

The single-entry and single-exit rule must also be maintained in a hierarchical structure of a program formed by module calls.

单入口和单出口规则也必须在由模块调用形成的程序的层次结构中进行维护。

下面这张图展示了层次结构中,进行模块调用。各模块都是单进单出

The advantages of structured programming 模块化设计的优点

  • The program has a good readability due to the fact that the program execution flow is consistent with the control flow presented in the program (code).

    由于程序执行流与程序(代码)中展现出的控制流一致,因此程序具有良好的可读性。

  • A structured program is easy to test.

    结构化程序很容易测试。

  • A structured program is easier for correctness proof than an unstructured program.

    结构化程序比非结构化程序更容易证明正确性。

Structured design usually means the combination of top-down design, modular design, and hierarchical design to realize a hierarchical structure of the software with good modularity.

结构化设计通常是指自顶向下的设计、模块化设计和层次化设计相结合,以实现具有良好模块性的软件的层次结构。

Structured design = Top-down design +Modular design +Hierarchical design

结构化设计=自顶向下的设计+模块化设计+层次化设计

I.6.5 Object-oriented design 面向对象设计

Object-oriented design (OOD) provides a method for designing software by focusing on defining objects and their relations.

面向对象设计提供了一种专注于定义对象及其关系的软件设计方法。

In other words, using OOD, we need to focus onidentifying and defining necessary objects and their relations.

换句话说,使用面向对象设计,我们需要专注于识别和定义必要的对象及其关系。

就是对象和对象之间的关系

Question ? 问题

  • (1)What is an object?

    什么是对象?

  • (2)How to represent an object in programs?

    如何在程序中表示对象

  • (3)How to define objects in programs?

    如何在程序中定义对象?

My answer: 老师的回答

  • (1)An object is anything in the real world. For example, house, desk, computer, smart phone, watch.

    物体是现实世界中的任何东西。例如,房子、桌子、电脑、智能手机、手表。

  • (2) An object is represented by encapsulation of its data and operations.

    对象通过其对数据和运算的封装来表示。

  • (3)Class is used to define objects.

    类可以用来定义对象

The structure of an object-oriented program is a network of objects:

面向对象程序的结构是一个对象网络:

像是结构化设计的拓展,但是把modular换成obj,对数据的使用也由一次变成可多次

I.6.6 Component-based design 基于组件的设计

Component-based design is a method for designing software using well-constructed software components.

基于组件的设计是一种使用构造良好的软件组件来设计软件的方法。

省时省钱可复用

A software component is a software module with the following characteristics:

软件组件是具有以下特征的软件模块:

  • A component be used directly in a program by just simply importing it.

    只要简单地引入一个组件,就可以直接在程序中使用它。

  • The interface and functionality of a component are well defined.

    组件的接口和功能都被定义好了

  • A component is usually programming language specific.

    与具体的编程语言有关

For example, in the Application Programming Interface (API) Java AWT and SWING, necessary components for building GUIs are provided.

例如,在应用程序编程接口Java AWT和SWING中,提供了构建图形化界面所需的组件。

Exercise 1 练习1

(1) Using T.V. set as an example to explain the following concepts:

以电视机为例,解释下列概念

Reliability

Efficiency

Usability

Maintainability

Reusability

Robustness

(2)Use the construction of a house as an example to explain the following design methods:

以房屋建筑为例,说明以下设计方法:

Top-down design

Bottom-up design

Modular design