- ch11 Design Concepts (重点)
- ch12 Architectural Design
- ch13 Component-level Design
Software Design
使用UML的面向对象设计建模
一个面向对象系统由相互交互的对象组成。
案例——业务气象站1
简单框图
注意:
1..n // 表示一对多
用例图
用况图/用例图——需要进一步用table来说明
案例——业务气象站2
类图
顺序图
状态图
接口规格说明
温习结束~
ch11 Design Concepts
- Design within the Context of Software Engineering
- The Design Process
- Design Concepts
- The Design Model
Software design is the process of transforming requirements into software statements (expressions).
11-1 Design Engineering
- Data/class design
- transforms class models into design class and data structure of target software; (数据结构)
- Architecture design
- defines the relationship between the major structural elements of the software; (整体结构)
- Interface design
- describes the communication between software and collaboration system, and between software and users; (接口)
- Component level design
- transforms the structural elements of software architecture into a procedural description of software components. (内部细节)
11.2 The Design Process
- Quality Guidelines 质量指导原则
- Quality Attributes 质量属性
- The evolution of software design 通用设计任务集
11.2-1 Quality Guidelines
11.2-2 Quality Attributes – FURPS model
- Functionality 功能性
- Usability 可用性
- Realiability 可靠性
- Performance 性能
- Supportability 可支持性/耐受性
通用设计任务集(软件演化):
11.3 Design Concepts(非常重要)
- 1 Abstraction 抽象
- 2 Architecture 架构
- 3 Patterns 模式
- 4 Separation of Concerns 关注点分离
- 5 Modularity 模块化
- 6 Information Hiding 信息隐藏
- 7 Functional Independence 功能独立
- 8 Refinement 求精
- 9 Refactoring/reconstruction 重构
- 10 Object Oriented Design Concept 面向对象的设计
- 11 Design Classes 设计类
- 12 Dependence Inversion 依赖倒置
- 13 Design for Test 测试设计
1 Abstraction
Abstract process: from special to general, the upper concept is the abstraction of the lower concept, and the lower concept is the refinement of the upper concept.
从特殊到一般,上层概念是下层概念的抽象,下层概念是上层概念的精炼;
软件开发过程的每一步都是对较高一级抽象的解,作一次具体化的描述。
- Data 数据抽象:描述数据对象的数据集合
- Process 过程抽象:具有明确和有限功能的指令序列
2 Architecture
- A set of attributes
- Structural properties
- Extra-functional properties
- Families of related systems
体系结构是程序构件 ( 模块 ) 的结构和组织、这些构件交互的形式以及这些构件所用数据的结构。
3 Pattern
Design patterns are proven solutions to recurring, specific problems in a specific environment.
设计模式是经过验证的,用于解决在特定环境下、重复出现的、特定问题的解决方案。
4 Separation of Concerns 关注点分离
2022年考点:
Separation of concerns indicates that any complex problem can be more easily handled if it is decomposed into several blocks that can be solved and/or optimized independently.
By dividing the concerns into smaller ones (resulting in more manageable blocks), it requires less work and time to solve a problem.
5 Modularity
- Design principles
- These modules are independent but interrelated.
- It is actually a process of system decomposition and abstraction.
- Modules are relatively independent program bodies
2022年考点:
Modularity is to divide the program into independently named and directly accessible modules. Each module completes a subfunction. These modules are integrated to form a whole and complete the specified function.
模块化就是把程序划分成独立命名且可直接访问的模块,各个模块完成一个子功能,这些模块集成起来构成一个整体,完成指定功能。
适度的模块化 Moderate modularity
Conclusion: To find the best balance point of modularization degree.
模块化的优点adv
- Make the development work easier to plan; (更易于规划)
- Software increment can be defined and delivered; (定义和交付软件增量)
- Easier implementation of changes; (更容易实施变更)
- Be able to carry out testing and debugging more effectively; (测试和调试)
- Long term maintenance can be carried out without serious side effects.(长期维护而没有严重的副作用)
6 Information Hiding 信息隐蔽
- 每个模块都尽量对其他模块隐藏自己的内部实现细节;
- 信息隐蔽是实现抽象 / 模块化机制的基本支撑;
信息隐蔽adv
- Concealed 隐藏 externally to reduce the possibility of side effects; 减少副作用
- Emphasize communication through control interface; 强调通过控制接口进行通信
- The use of global data is discouraged; 不鼓励使用全局数据
- Use encapsulation – an attribute of high-quality design; 使用封装
- It can produce high-quality software. 产生高质量软件
7 Functional Independence
Functional independence is the direct result of separation of concerns, modularity, abstract concept and information hiding.
功能独立是关注点分离、模块化、抽象概念和信息隐蔽的直接结果。
功能独立性的指标(追求高内聚、低耦合)
- 内聚 (Cohesion) :模块内部各个元素结合的紧密程度(由独立性弱到强排序)
- 巧合内聚 Coincident cohesion(低内聚,独立性弱)
- 将几个模块中的相同程序代码段独立出来建立的模块(无明显独立性)
- 逻辑内聚 Logic cohesion
- 完成一组逻辑相关任务的模块,由控制型参数来确定执行哪一种功能
- 事件内聚 Time cohesion
- 模块中的多个任务必须在一段时间内先后执行(有时间约束,无过程)
- 过程内聚 Process cohesion
- 模块内的多个任务必须按指定的过程执行
- 通信内聚 Communication cohesion
- 模块内所有处理元素都集中在某个数据结构的一块区域(选退课)
- 顺序内聚 Sequential cohesion
- 指一个模块完成多个功能,这些功能又必须顺序执行
- 功能内聚:Function cohesion(高内聚,独立性强)
- 一个模块中各个部分都是为完成一项具体功能而协同工作
- 耦合 (Coupling):模块之间相互关联的程度(由独立性弱到强排序)
- 内容耦合 Content coupling(高耦合,独立性弱)
- 一个模块可以直接访问另一个模块的内部数据或内部功能
- 公共耦合 Public coupling
- 多个模块共同访问某些公共元素数据
- 外部耦合 External coupling
- 多个模块间需要遵循同样的外部约束
- 控制耦合 Control coupling
- 模块间的交互参数包含控制信息,可影响另一个模块的执行逻辑
- 标记耦合 Tag coupling
- 模块间传递特定的数据结构
- 数据耦合 Data coupling
- 模块间仅传递简单数据
- 非直接耦合 Indirect coupling(低耦合,独立性强)
- 两个模块可以相对独立工作
- 内聚度 Cohesion
- 耦合度 Coupling
耦合的具体案例(独立性)
- Content coupling
- Public coupling
- Control coupling
- Data coupling
- Content coupling: one module can directly access the internal data or functions of another module(内容耦合,最不可取的情况)
- Public coupling: Multiple modules access some common data elements together (公共耦合)
- Control coupling(控制耦合)
模块间的交互参数包含控制信息,可影响另一个模块的执行逻辑。
The interaction parameters between modules contain control information, which can affect the execution logic of another module.
- Data coupling: only simple data is transferred between modules.
Summary for Functional Independence
- 高内聚、低耦合:high cohesion and low coupling
8 Refinement 求精
Refinement: refinement of various abstractions
求精:对各种抽象的细化
逐步求精:为了集中精力解决主要问题而尽量推迟对细节的考虑,是一种自顶向下的设计策略:(Step by step refinementm,top-down design strategy)
9 Refactoring/Reconstruction 重构
Do not change the external behavior of the code [design], but change its internal structure.
重构:是一种重新组织的技术,可以简化构件的设计(或代码),而无需改变其功能或行为。不改变代码的外部行为,而是改变其内部结构。
10 Object Oriented Design Concept 面向对象的设计概念
- 11 Design Class
- User Interface class 用户接口类
- Business domain class 业务领类
- Process class 过程类
- Presistent class 持久类
- System class 系统类
- Four characteristics of well-formed design class
- Complete and sufficiency 完整性与充分性
- Primitiveness 原始性
- High cohesion & Low coupling 高内聚+低耦合
12 Dependence Inversion 依赖倒置
- 高层模块(类)不应当(直接)依赖 于低层模块,两者都应当依赖于抽象。
- 抽象不应当依赖于细节,细节应当依赖于抽象。
13 Design for Test
- 测试要快,失败要快,调整要快
11.4 The Design Model 设计模型
- 体系结构设计元素 Architecture design elements
- Application domain information 应用域信息
- Specific requirements model elements 特定的需求模型元素
- Architecture pattern 体系结构模型
- 接口设计元素 Interface design elements
- User Interface UI设计
- External interfaces with other systems 外部接口
- Internal interfaces 内部借口
- 构建级设计元素 Component-level design elements
- defines data structures 定义数据结构
- defines algorithm details 定义算法细节
- Define interfaces (that allow access to all component operations) 接口
软件体系结构设计元素为我们提供了软件的整体视图。
软件接口设计元素描述了信息如何流入和流出系统以及被 定义为体系结构一部分的构件之间是如何通信的。
UML Class Diagram中的接口
ch12 Architectural Design
12.3 Architectural Styles
- Data-Centered Architectures 以数据为中心
- Data-Flow Architectures 数据流
- Call and Return Architectures 调用和返回体系结构
- Object-Oriented Architectures 面向对象体系结构
- Layered Architectures 层次体系结构
使用数据流进行体系结构映射 Data-Flow Architectures
- 两种信息流类型
- 变换型
- 信息沿着各种路径进入系统,这些路径称为输入流。
- 事务型
- 将外部信息转换成一个事务,对事务进行评估,并且根据评估结果,启动其中一条(也可能是若干条)动作路径流
- 变换型是线性的处理,事务型是分类处理
两者区别
ch13 Component-level Design
体系结构设计和构建级设计的联系:
13.1 Component
13.2 Designing Class-Based Components
- Open-Closed Principle (OCP) 开闭原则
- 模块应该对外具有开放性,对内具有封闭性
- Liskov Substitution Principle (LSP) Liskov替换原则
- 子类可以替换它们的基类
- Dependency Inversion Principle (DIP) 依赖倒置原则
- 依赖于抽象,而非具体实现
- Interface Segregation Principle (ISP) 接口分离原则
- 多个用户专用接口比一个通用接口要好
2021年考题
Cohesion & Coupling 内聚耦合汇总
- 内聚 (Cohesion) :模块内部各个元素结合的紧密程度(由独立性弱到强排序)
- 巧合内聚 Coincident cohesion(低内聚,独立性弱)
- 将几个模块中的相同程序代码段独立出来建立的模块(无明显独立性)
- 逻辑内聚 Logic cohesion
- 完成一组逻辑相关任务的模块,由控制型参数来确定执行哪一种功能
- 事件内聚 Time cohesion
- 模块中的多个任务必须在一段时间内先后执行(有时间约束,无过程)
- 过程内聚 Process cohesion
- 模块内的多个任务必须按指定的过程执行
- 通信内聚 Communication cohesion
- 模块内所有处理元素都集中在某个数据结构的一块区域(选退课)
- 顺序内聚 Sequential cohesion
- 指一个模块完成多个功能,这些功能又必须顺序执行
- 功能内聚:Function cohesion(高内聚,独立性强)
- 一个模块中各个部分都是为完成一项具体功能而协同工作
- 耦合 (Coupling):模块之间相互关联的程度(由独立性弱到强排序)
- 内容耦合 Content coupling(高耦合,独立性弱)
- 一个模块可以直接访问另一个模块的内部数据或内部功能
- 公共耦合 Public coupling
- 多个模块共同访问某些公共元素数据
- 外部耦合 External coupling
- 多个模块间需要遵循同样的外部约束
- 控制耦合 Control coupling
- 模块间的交互参数包含控制信息,可影响另一个模块的执行逻辑
- 标记耦合 Tag coupling
- 模块间传递特定的数据结构
- 数据耦合 Data coupling
- 模块间仅传递简单数据
- 非直接耦合 Indirect coupling(低耦合,独立性强)
- 两个模块可以相对独立工作
Cohesion: as the “single-mindedness” of a component.
Cohesion implies that a component or class encapsulates only attributes and operations
A qualitative measure of the closeness among components.
With the increase of component interdependence, the coupling degree of components will also increase.
- 内聚 Cohesion 例子
Sequential cohesion
Time cohesion
Logical cohesion
Common(Coincident) Cohesion
Communication Cohesion
Sequential Cohesion
Functional Cohesion
- 耦合 Coupling 例子
Content Coupling
Common Coupling
Control Coupling
标记耦合(特征耦合)Tag coupling
Data Coupling
模块关联的评价指标