1 / 67

面向对象技术

面向对象技术. 相关信息. 教师:余萍 Email: yuping@nju.edu.cn Office: 蒙民伟楼 610A 助教 课程网页: http://cs.nju.edu.cn/yuping/. 引言. 摘要. 课程简介 --“选不选这门课?” 背景概述 --“所学内容在专业知识结构中的位置?”. 欢迎选修“面向对象技术” !. 通过选修本课程,可以 更深入地掌握面向对象的基本原理 更广泛地了解面向对象的新兴技术 更自信地面对实际开发的技术需求 获取 3 个学分. 课程性质. 不是又一门语言 / 编程课

juanita
Download Presentation

面向对象技术

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 面向对象技术

  2. 相关信息 • 教师:余萍 • Email: yuping@nju.edu.cn • Office: 蒙民伟楼610A • 助教 • 课程网页:http://cs.nju.edu.cn/yuping/ Institute of Computer Software Nanjing University

  3. 引言

  4. 摘要 • 课程简介 --“选不选这门课?” • 背景概述 --“所学内容在专业知识结构中的位置?” Institute of Computer Software Nanjing University

  5. 欢迎选修“面向对象技术”! • 通过选修本课程,可以 • 更深入地掌握面向对象的基本原理 • 更广泛地了解面向对象的新兴技术 • 更自信地面对实际开发的技术需求 • 获取 3 个学分 Institute of Computer Software Nanjing University

  6. 课程性质 • 不是又一门语言/编程课 • 虽然在C++/Java 之外还会提到别的语言,如Eiffel • 不是一般意义上的软件工程课 • 但讲授面向对象软件开发的实用技术 • 不属于理论计算机科学 • 但会利用一些较成熟易用的理论工具 Institute of Computer Software Nanjing University

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

  8. 课程内容 主要包括但不限于: • 面向对象的起源及其动机 • 面向对象技术的核心概念和基本原理 • Object, Class, Encapsulation, Polymorphism, …… • Abstract Data Type, Design by Contract, …… • Garbage Collection, Exception Handling, …… • 面向对象技术的应用 • Design Patterns, Application Frameworks • 面向对象的发展 • 并发、分布对象计算、服务计算,…… • 面向对象分析/开发/测试 • AOP Institute of Computer Software Nanjing University

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

  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. • Craig Larman, Applying UML and Patterns, Prentice Hall PTR, 2nd edition. 2001. • Clemens Szyperski. Component Software: Beyond Object-Oriented Programming. Addison-Wesley, 2nd edition, 2002. Institute of Computer Software Nanjing University

  11. 授课方式 • Lecture • Seminar Institute of Computer Software Nanjing University

  12. 考核方式 • 笔试 50% • 开卷 or 闭卷? • 平时 50% • 其中 • 书面作业 25% (态度第一) • 开发练习 25% (一个月后公布具体要求) • 主动Presentation 约 20-30% (额外加分) • 理论探索,学习心得,实践经验 均可 Institute of Computer Software Nanjing University

  13. 有何建议 • 课程内容? • 授课方式? • 考核方式? • 其他? Institute of Computer Software Nanjing University

  14. 背景概述

  15. 摘要 • 从软件到软件工程 • 软件质量 • 前对象时代 • 结构化程序设计 • 面向对象思想的兴起 • 模块化 • 软件复用 Institute of Computer Software Nanjing University

  16. 软件 • 概念 • 一系列按照特定顺序组织的数据和指令的集合 • 程序+文档 • 程序:计算任务的处理对象和处理规则的描述 • 文档:为了便于了解程序所需的阐明性资料 • 特点 • 本质上是逻辑产品 • 现实中受多方制约 Institute of Computer Software Nanjing University

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

  18. 软件:逻辑产品 • 存储程序计算机在体系结构上主要特点有: • 以运算单元为中心 • 采用存储程序原理 • 存储器是按地址访问、线性编址的空间 • 控制流由指令流产生 • 指令由操作码和地址码组成 • 数据以二进制编码 Institute of Computer Software Nanjing University

  19. 软件:多方制约 • 作为一种“工程” • 目的性 • 资源 • 物理运行平台 • 工程问题 • 质量、生产率 • 根源:复杂性 • 软件工程:将系统化的、规范的、可度量的方法应用于软件的开发、运行和维护的过程,即将工程化应用于软件中。 1969,NATO会议 软件危机 Institute of Computer Software Nanjing University

  20. 软件 • 通常而言,“质量”与“生产率”是一对矛盾 • 我们首先来考虑“质量”。 • 有趣的是,在软件领域,对“质量”的重视有时竟然会带来“生产率”的提升! • 说明软件工程远未成熟,二者的“共同底线”还未达到。 Institute of Computer Software Nanjing University

  21. 软件质量 • 何谓“质量”? • 产品或工作的“优劣程度” • 何为“优”?何为“劣”? • 可从“外部” 和 “内部” 两个不同的侧面来考察软件产品 (Meyer, McCall) • 外部质量因素:用户直接感觉到的 • 内部质量因素:用户不能直接发觉,体现在软件“文本”(源码、设计报告、分析报告等)中 • Being modular; readable… Institute of Computer Software Nanjing University

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

  23. 外部质量因素 • Compatibility 兼容性 • 软件模块相互组合的难易 • Efficiency 高效性 • 尽量少地使用硬件资源 处理器时间 内存 外存 网络带宽 等 • Portability 易移植性 • 转换到不同的软硬件平台上 • Ease of use 易用性 • 不同背景的用户学习使用软件产品解决问题的难易 Institute of Computer Software Nanjing University

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

  25. 维护费用分类 70% of the cost of software is devoted to maintenance! [Lientz 1980] Institute of Computer Software Nanjing University

  26. Tradeoffs • 鱼与熊掌不可得兼 • 权衡 折中 • 软件技术研究的常见主题: • 在何种条件下 以何种方式 鱼与熊掌可以得兼? • 在何种条件下 拿部分鱼换取更多熊掌?何时反之? Institute of Computer Software Nanjing University

  27. Key Concerns • 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

  28. 应对软件危机 • 开发的角度:分析、设计方法的研究 • 前对象时代 • Structured Programming, Design, Analysis • 管理的角度:软件开发过程的工程化 • 生命周期模型 • 瀑布模型,快速原型法,螺旋模型,喷泉模型等 Institute of Computer Software Nanjing University

  29. 应对复杂性的基本途径 • “元方法” • Decomposition 分而治之 • Abstraction 抓本质,抓重点 • Hierarchy 应对大系统,纲举目张 复杂性是软件开发过程中所固有的特质。[Booch94] Institute of Computer Software Nanjing University

  30. 结构化开发方法 • 何谓“结构化”? • 结构化程序设计 • 设计过程 程序组织 语句构造 结构化 • 结构化分析设计 • 数据流图 数据字典 模块结构图 • 结构化的好处 • 科学化 可读性 模块化 信息隐蔽... Institute of Computer Software Nanjing University

  31. 结构化开发方法 • 自顶向下(Top-down) 的功能设计 Topmost functional abstraction 自顶向下,逐步求精 A Sequence B D C Conditional Loop C1 I I1 C2 I2 Institute of Computer Software Nanjing University

  32. 软件生命周期模型 FEASIBILITY STUDY 瀑布型 REQUIREMENTS ANALYSIS SPECIFICATION GLOBAL DESIGN DETAILED DESIGN • The activities are necessary. • (But: merging of middle activities.) • The order is the right one. IMPLEMENTATION VALIDATION & VERIFICATION DISTRIBUTION Institute of Computer Software, Nanjing University PROJECT PROGRESS

  33. The waterfall model of the lifecycle FEASIBILITY STUDY REQUIREMENTS ANALYSIS DESIGN AND IMPLEMENTATION SPECIFICATION GLOBAL DESIGN DETAILED DESIGN IMPLEMENTATION VALIDATION & VERIFICATION DISTRIBUTION Institute of Computer Software, Nanjing University PROJECT TIME

  34. Problems with the waterfall • 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

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

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

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

  38. Five Criteria • Decomposability 易分解性 • Composability 易组合性 • Understandability 易理解性 • Continuity 连续性 • Protection 保护性 Institute of Computer Software Nanjing University

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

  40. 易组合性 Composability • Method favors production of software elements that may be freely combined with each other to produce new software. Example: Unix shell conventions Program1 | Program2 | Program3 Institute of Computer Software Nanjing University

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

  42. 连续性 Continuity • Method ensures that small changes in specifications yield small changes in architecture. • Design method: Specification Architecture • Example: Principle of Uniform Access (see next) • Counter example: static arrays Institute of Computer Software Nanjing University

  43. The Principle of Uniform Access • Facilities managed by a module are accessible to its clients in the same way whether implemented by computation or by storage. • Definition: A client of a module is any module that uses its facilities. Institute of Computer Software Nanjing University

  44. Uniform Access: An example balance = list_of_deposits.total – list_of_withdrawals.total list_of_deposits (A1) list_of_withdrawals balance 思考:C++和Java如何实现? list_of_deposits (A2) list_of_withdrawals Ada, Pascal, C/C++, Java, C#: Simula, Eiffel: A1: a.balancea.balance A2: balance (a) a.balance() Institute of Computer Software Nanjing University

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

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

  47. 直接映射 Direct mapping • Method yields software systems whose modular structureremains 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

  48. Few interfaces • 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

  49. Small interfaces • If two modules communicate, they exchange as little information as possible. x, y z Institute of Computer Software Nanjing University

  50. Explicit interfaces • 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

More Related