软件构造的多维度视图和质量目标
1.软件构造的多维度视图和质量目标
Multi-dimensional software views
Constituents of a software system
Software = Program + Data + Documents
Software = Modules(Components) + Data/Control Flows

软件的多维视图

Build-time views
Code-level view:代码的逻辑组织
Component-level view:代码的物理组织
- Moment view:特定时刻的软件形态
- Period view:软件随时间的变化
Build-time, moment, and code-level view
词汇层面: 面向词法的源代码
半结构化的源代码:近乎自然语言的风格+遵循特定的编程语法
语法层面:面向语法的程序结构(例子:抽象语法树(AST))
1
2
3
4
5
6
7while (a != b) {
if (a > b)
a = a - b;
else
b = b - a;
}
return a;

语义层面:面向语义的程序结构(例子:类图(Class Diagram))
用Class Diagram描述接口,类,属性,方法以及他们的关系。
通常是图形化的,在设计阶段被模型化,然后转换成源代码。
由面向对象的分析和设计产生的满足用户需求的结果。

Build-time, period, and code-level view
描述“变化”的视图。
代码变化:Lines added, modified or deleted to a file from one version to another.
Build-time, moment, and component-level view
源代码被物理地组织为文件,文件被目录所组织。
文件被封装成包,在逻辑上被封装成组件和sub-systems。
可复用的模块以库的形式存放。
- 库:被储存为磁盘文件。开发者像使用编程语言指令一样使用库的功能。来源包括:操作系统、编程语言(SDK)、第三方公司、自己积累。
- 静态链接:库被拷贝进入代码,执行时无需提供库文件。
Build-time, period, and component-level view
Software Configuration Item (SCI,配置项)
Version (版本)
- Version Control System (VCS)

Runtime Views
- 代码层面:逻辑实体在内存中如何 呈现?
- 构件层面:物理实体在物理硬件环境中如何呈现?
- 逻辑/物理实体 在内存/硬件环境中特定时刻的形态如何?
- 逻辑/物理实体在内存/ 硬件环境中的形态随时间如何变化?
原生机器码:最快的方式(because the program full accesses to the CPU’s features)
动态链接:库文件不会在build阶段被加入可执行软件,仅仅做出标记。运行时根据标记装载至内存。
配置文件和数据文件
分布式程序的运行态:需要多个运行程序,分别部署于多个计算机物理环境。
Run-time, moment, and code-level view
- Snapshot diagram(代码快照图):描述程序运行时内存里变量层面的状态。
- Memory dump(内存信息转储):一个储存在硬盘上的文件,是程序运行过程中内存的副本,产生于abort时,可用于分析错误。
Run-time, period, and code-level view
Sequence diagram in UML: interactions among program units

- Execution tracing:用日志方式记录程序执行的调用次序。
Run-time, moment, and component-level view
Deployment diagram in UML

Run-time, period, and component-level view
系统层面的事件日志:提供给系统管理员一些对诊断和核对有用的信息。
Software construction: Transformation between views

Types of Transformations in Software Construction
$ \phi \to Code $
Programming / Coding (ADT/OOP)
$Code \to Component$
Design(ADT/OOP; Reusability; Maintainability)
$Build-time \to Run-time$
Install / Deploy
Debug, unit/integration testing
$Moment \to Period$
Version control
Quality properties of software systems
- External quality factors: 对用户有影响,可被用户检测到的因素(速度,易用性等)
- Internal quality factors:对软件本身和开发者有影响的要素(可读性,模块化等)
外部质量取决于内部质量
External quality factors
1:Correctness
按照预先定义的规约执行,是最重要的质量指标
Method
测试和调试:发现不正确、消除不正确
防御式编程:在写程序的时候就确保正确性
形式化方法:通过形式化验证发现问题
2:Robustness
健壮性(鲁棒性):针对异常情况的处理。
健壮性是对正确性的补充,对出现规约定义之外的行为时,要求软件做出恰当的反应。(至少不要崩溃)
3:Extendibility
对软件的规约进行修改,是否足够容易?
规模越大,扩展起来越不容易
Two principles are essential for improving extendibility
Design simplicity : 简约主义设计
Decentralization : 分离主义设计
4:Reusability
一次开发,多次使用。
不要重复造轮子!
5:Compatibility
不同的软件系统之间相互可容易的集成。
兼容性的重要之处在于,软件不是独立运作的,而是需要与其他软件交互的(包括运行环境)。
保持设计的同构性,对兼容性进行标准化。
6:Efficiency
性能毫无意义,除非有 足够的正确性。
对性能的关注要与其他质量属性进行折中。
过度的优化导致软件不再适应变化和复用。
7:Portability
软件可方便的在不同的技术环境之间移植。(包含硬件和操作系统)
8:Ease of use
易用性:容易学、安装、操作、监控。
给用户提供详细的指南。
9:Functionality
Functionality is the extent of possibilities provided by a system.
- Featurism:程序设计中一种不适宜的趋势,即软件开发者增加越来越多的功能,企图跟上竞争,其结果是程序极为复杂、不灵活、占用过多的磁盘空间。
10:Timeliness
Timeliness (及时性) is the ability of a software system to be released when or before its users want it.
A great software product that appears too late might miss its target altogether.
Others
Verifiability
Integrity
Repairability
Economy
Internal quality factors
- Readability
- Understandability
- Clearness
- Size
Tradeoff between quality properties
- Integrity $\Longleftrightarrow$ Ease of use
- Economy $\Longleftrightarrow$ Functionality, (reusability)
- Efficiency $\Longleftrightarrow$ Portability, reusability
- Timeliness(“Rapid Application Development”) $\Longleftrightarrow$ Extendibility
How OOP improves quality
- Correctness: encapsulation, decentralization
- Robustness: encapsulation, error handling
- Extendibility: encapsulation, information hiding
- Reusability: modularity, component, models, patterns
- Compatibility: standardized module and interface
- Portability: information hiding, abstraction
- Ease of use: GUI components, framework
- Efficiency: reusable components
- Timeliness: modeling, reuse
- Economy: reuse
- Functionality: extendibility
Five key quality objectives of software construction
- Easy to understand: elegant and beautiful code / understandability
- Ready for change: maintainability and adaptability
- Cheap for develop: design for/with reuse: reusability
- Safe from bugs: robustness
- Efficient to run: performance