1 Institute of Computer Software Nanjing University 2

  • Slides: 65
Download presentation
1 面向对象技术 Institute of Computer Software, Nanjing University

1 面向对象技术 Institute of Computer Software, Nanjing University

相关信息 2 教师:余萍 Email: yuping@nju. edu. cn Office: 仙林计算机系大楼 818 助教 课程网页:http: //cs. nju.

相关信息 2 教师:余萍 Email: yuping@nju. edu. cn Office: 仙林计算机系大楼 818 助教 课程网页:http: //cs. nju. edu. cn/yuping/ Institute of Computer Software Nanjing University 2020/11/30

课程目标 7 用OOPL写代码 → OOP → OOSC 朴素的OOP → 系统化的OOP 传统OO技术 → 现代的OO技术 Beyond

课程目标 7 用OOPL写代码 → OOP → OOSC 朴素的OOP → 系统化的OOP 传统OO技术 → 现代的OO技术 Beyond OO Institute of Computer Software Nanjing University 2020/11/30

教材与参考资料 9 徐家福, 王志坚, 翟成祥 等,《对象式程序设计语言 》, 南京大学出版社,1993年 2月。 Bertrand Meyer, Object-Oriented Software Construction,

教材与参考资料 9 徐家福, 王志坚, 翟成祥 等,《对象式程序设计语言 》, 南京大学出版社,1993年 2月。 Bertrand Meyer, Object-Oriented Software Construction, Second Edition, Prentice Hall, 1997. 清华大学出版社影印。 Jolt Award 1998 Institute of Computer Software Nanjing University 2020/11/30

教材与参考资料 10 Richard Mitchell and Jim Mckim. Design by Contract, by Example. Erich Gamma,

教材与参考资料 10 Richard Mitchell and Jim Mckim. Design by Contract, by Example. Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, Design Patterns: Elements of Reusable Object-Oriented software, Addison-Wesley , 1994. Robert C. Martin. Agile Software Development, Principles, Patterns and Practices,2003. Clemens Szyperski. Component Software: Beyond Object-Oriented Programming. Addison-Wesley, 2 nd edition, 2002. Joseph D. Gradecki, Nicholas Lesiecki. Mastering Aspect. J. Institute of Computer Software Nanjing University 2020/11/30

有何建议 12 课程内容? 授课方式? 考核方式? 其他? Institute of Computer Software Nanjing University 2020/11/30

有何建议 12 课程内容? 授课方式? 考核方式? 其他? Institute of Computer Software Nanjing University 2020/11/30

软件:逻辑产品 16 基础: 图灵机, 1936 冯·诺依曼结构, 1945 Alan Turing: 抽象计 算模型(数学逻辑机) Institute of Computer

软件:逻辑产品 16 基础: 图灵机, 1936 冯·诺依曼结构, 1945 Alan Turing: 抽象计 算模型(数学逻辑机) Institute of Computer Software Nanjing University 2020/11/30

外部质量因素 21 Correctness 正确性 Robustness 鲁棒性 异常情况 合理反应 SPECIFICATION 非法访问或修改 合理反应 Extendibility 易扩展性 Reliability

外部质量因素 21 Correctness 正确性 Robustness 鲁棒性 异常情况 合理反应 SPECIFICATION 非法访问或修改 合理反应 Extendibility 易扩展性 Reliability 可靠性 Integrity 完整性 依据规约 完成任务 软件产品 应 规约改变 而 改变 Correctness Robustness Integrity Reusability 易复用性 软件模块 用于构建多种不同应用 Institute of Computer Software, Nanjing University 2020/11/30

外部质量因素 23 Functionality 功能 Timeliness 按时交付 Verifiability, Reparability, Economy Institute of Computer Software Nanjing

外部质量因素 23 Functionality 功能 Timeliness 按时交付 Verifiability, Reparability, Economy Institute of Computer Software Nanjing University 2020/11/30

维护费用分类 24 软件 70%的费用花在维护上! [Lientz 1980] Institute of Computer Software Nanjing University 2020/11/30

维护费用分类 24 软件 70%的费用花在维护上! [Lientz 1980] Institute of Computer Software Nanjing University 2020/11/30

Key Concerns 26 Reliability [correctness + robustness]: It should be easier to build software

Key Concerns 26 Reliability [correctness + robustness]: It should be easier to build software that functions properly, and easier to guarantee what it does. Modularity [reusability + extendibility]: We should build less software! Software should be easier to modify. Institute of Computer Software, Nanjing University 2020/11/30

应对复杂性的基本途径 28 “元方法” 分解Decomposition 抽象Abstraction 层次化Hierarchy 分而治之 抓本质,抓重点 应对大系统,纲举目张 Institute of Computer Software Nanjing

应对复杂性的基本途径 28 “元方法” 分解Decomposition 抽象Abstraction 层次化Hierarchy 分而治之 抓本质,抓重点 应对大系统,纲举目张 Institute of Computer Software Nanjing University 2020/11/30

结构化开发方法 30 自顶向下(Top-down) 的功能设计 Topmost functional abstraction 自顶向下,逐步求精 A Sequence B D C Conditional

结构化开发方法 30 自顶向下(Top-down) 的功能设计 Topmost functional abstraction 自顶向下,逐步求精 A Sequence B D C Conditional Loop C 1 I I 1 C 2 Institute of Computer Software Nanjing University 2020/11/30

软件生命周期模型 31 FEASIBILITY STUDY 瀑布型 REQUIREMENTS ANALYSIS SPECIFICATION GLOBAL DESIGN DETAILED DESIGN IMPLEMENTATION VALIDATION

软件生命周期模型 31 FEASIBILITY STUDY 瀑布型 REQUIREMENTS ANALYSIS SPECIFICATION GLOBAL DESIGN DETAILED DESIGN IMPLEMENTATION VALIDATION & VERIFICATION PROJECT PROGRESS DISTRIBUTION Institute of Computer Software, Nanjing University 2020/11/30

Problems with the waterfall 32 Late appearance of actual code. Lack of support for

Problems with the waterfall 32 Late appearance of actual code. Lack of support for requirements change — and more generally for extendibility and reusability. Lack of support for the maintenance activity (70% of software costs). Division of labor hampering Total Quality Management. Impedance mismatches. Highly synchronous model. WARNING: The waterfall model is not the recommended process model for O-O development Institute of Computer Software, Nanjing University 2020/11/30

Quality Control? 33 Analysts Designers Implementers Testers Customers Institute of Computer Software, Nanjing University

Quality Control? 33 Analysts Designers Implementers Testers Customers Institute of Computer Software, Nanjing University 2020/11/30

Impedance mismatches 34 As Management requested it. As Programming developed it. As the Project

Impedance mismatches 34 As Management requested it. As Programming developed it. As the Project Leader defined it. As Operations installed it. As Systems designed it. What the user wanted.

软件模块化 35 概念 模块(module): “Self-Contained”; well-defined interfaces 模块化(modular): 软件构造为一组“模块”之有序组合,从而 易于装配、易于修补替换模块。 Extendibility 和 Reusability 的要求;

软件模块化 35 概念 模块(module): “Self-Contained”; well-defined interfaces 模块化(modular): 软件构造为一组“模块”之有序组合,从而 易于装配、易于修补替换模块。 Extendibility 和 Reusability 的要求; 模块化是上述“元方法”的推论。 什么样的方法是“模块化”的? 目标(Five Criteria) 规则(Five Rules) Institute of Computer Software Nanjing University 2020/11/30

Five Criteria 36 Decomposability 易分解性 Composability 易组合性 Understandability 易理解性 Continuity 连续性 Protection 保护性 Institute

Five Criteria 36 Decomposability 易分解性 Composability 易组合性 Understandability 易理解性 Continuity 连续性 Protection 保护性 Institute of Computer Software Nanjing University 2020/11/30

易分解性 Decomposability 37 Method helps decompose complex problems into subproblems. COROLLARY: Division of labor.

易分解性 Decomposability 37 Method helps decompose complex problems into subproblems. COROLLARY: Division of labor. Counter-example: General initialization module. Institute of Computer Software Nanjing University 2020/11/30

易组合性 Composability 38 Method favors production of software elements that may be freely combined

易组合性 Composability 38 Method favors production of software elements that may be freely combined with each other to produce new software. Example: Unix shell conventions Program 1 | Program 2 | Program 3 Institute of Computer Software Nanjing University 2020/11/30

易理解性 Understandability 39 模块应可单独理解 不能牵涉太广 自描述 Counter example: sequential dependencies A|B|C Institute of Computer

易理解性 Understandability 39 模块应可单独理解 不能牵涉太广 自描述 Counter example: sequential dependencies A|B|C Institute of Computer Software Nanjing University 2020/11/30

连续性 Continuity 40 Method ensures that small changes in specifications yield small changes in

连续性 Continuity 40 Method ensures that small changes in specifications yield small changes in architecture. Design method: Specification Architecture Counter example: static arrays Institute of Computer Software Nanjing University 2020/11/30

模块保护 Protection 41 异常不扩散 扩散范围有限 Example: validating input at the source Counter example: undisciplined

模块保护 Protection 41 异常不扩散 扩散范围有限 Example: validating input at the source Counter example: undisciplined exceptions Protection violation Institute of Computer Software Nanjing University 2020/11/30

Five Rules 42 Direct Mapping 直接映射 Few Interfaces 接口要少 Small Interfaces 接口要小 Explicit Interfaces

Five Rules 42 Direct Mapping 直接映射 Few Interfaces 接口要少 Small Interfaces 接口要小 Explicit Interfaces 接口要明确 Information Hiding 信息隐蔽 降低耦合度 Institute of Computer Software Nanjing University 2020/11/30

直接映射 Direct mapping 43 Method yields software systems whose modular structure remains compatible with

直接映射 Direct mapping 43 Method yields software systems whose modular structure remains compatible with any modular structure devised in the process of modeling the problem domain. model Structure of the problem direct mapping Structure of the solution software Institute of Computer Software Nanjing University 2020/11/30

Few interfaces 44 Every module communicates with as few others as possible. (A) (B)

Few interfaces 44 Every module communicates with as few others as possible. (A) (B) (C) n-1 n(n-1)/2 n-1 Institute of Computer Software Nanjing University 2020/11/30

Small interfaces 45 If two modules communicate, they exchange as little information as possible.

Small interfaces 45 If two modules communicate, they exchange as little information as possible. x, y z Institute of Computer Software Nanjing University 2020/11/30

Explicit interfaces 46 Whenever two modules A and B communicate, this is obvious from

Explicit interfaces 46 Whenever two modules A and B communicate, this is obvious from the text of A or B or both. Counter example: data sharing Module A Module B Modifies Accesses Data item x Institute of Computer Software Nanjing University 2020/11/30

Information hiding 47 Underlying question: how does one “advertise” the capabilities of a module?

Information hiding 47 Underlying question: how does one “advertise” the capabilities of a module? Every module should be known to the outside world through an official, “public” interface. The rest of the module’s properties comprises its “secrets”. It should be impossible to access the secrets from the outside. Institute of Computer Software Nanjing University 2020/11/30

Information Hiding 48 The designer of every module must select a subset of the

Information Hiding 48 The designer of every module must select a subset of the module’s properties as the official information about the module, to be made available to authors of client modules. Public part Secret part Institute of Computer Software Nanjing University 2020/11/30

软件复用 50 为什么要复用? 复用什么? 问题 非技术 技术 解决途径? Institute of Computer Software Nanjing University

软件复用 50 为什么要复用? 复用什么? 问题 非技术 技术 解决途径? Institute of Computer Software Nanjing University 2020/11/30

为什么要“复用” 51 “懒惰” 提高生产率 改善质量 Institute of Computer Software Nanjing University 2020/11/30

为什么要“复用” 51 “懒惰” 提高生产率 改善质量 Institute of Computer Software Nanjing University 2020/11/30

非技术障碍 53 心理 不信任 旧习惯 短期利益 构件检索 构件发布 与 商业模型 Institute of Computer Software

非技术障碍 53 心理 不信任 旧习惯 短期利益 构件检索 构件发布 与 商业模型 Institute of Computer Software Nanjing University 2020/11/30

技术问题 54 复用的本质困难 通常不能一成不变地拿来就用 Reusability Extensibility 软件的开放性要求和封闭性要求之间的冲突 open for extension, but closed for modification

技术问题 54 复用的本质困难 通常不能一成不变地拿来就用 Reusability Extensibility 软件的开放性要求和封闭性要求之间的冲突 open for extension, but closed for modification 对象技术比传统技术有明显改善 为什么? Institute of Computer Software Nanjing University 2020/11/30

传统技术复用支持 56 包 package Linguistic Modular Unit Features (变量 过程) 信息隐蔽 单独编译 Institute of

传统技术复用支持 56 包 package Linguistic Modular Unit Features (变量 过程) 信息隐蔽 单独编译 Institute of Computer Software Nanjing University 2020/11/30

Encapsulation languages (“Object-based”) 57 Ada, Modula-2, CLU. . . Basic idea: gather a group

Encapsulation languages (“Object-based”) 57 Ada, Modula-2, CLU. . . Basic idea: gather a group of routines serving a related oo-purpose, such as has, insert, remove etc. , together with the appropriate data structure descriptions. Advantages: For supplier author: Get everything under one roof. Simplifies configuration management, change of implementation, addition of new primitives. For client author: Find everything at one place. Simplifies search for existing routines, requests for extensions. Institute of Computer Software, Nanjing University 2020/11/30

基本概念 61 对象 类 封装性 继承性 多态性 动态绑定 消息传递 特性 Institute of Computer Software

基本概念 61 对象 类 封装性 继承性 多态性 动态绑定 消息传递 特性 Institute of Computer Software Nanjing University 2020/11/30