Microsoft Word - 物件導向編程精要.doc

Similar documents
(procedure-oriented)?? 2

Microsoft Word - ch04三校.doc

Strings

EJB-Programming-3.PDF

Microsoft PowerPoint - plan08.ppt

Microsoft Word - chap10.doc

1 C++ 2 Bjarne Stroustrup C++ (system programming) 6 (infrastructure) C++ 7 Herb Sutter 8 C++ (efficiency) (flexibility) 9 (abstraction) (productivity

前言 C# C# C# C C# C# C# C# C# microservices C# More Effective C# More Effective C# C# C# C# Effective C# 50 C# C# 7 Effective vii

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

Microsoft PowerPoint - L17_Inheritance_v4.pptx

Strings

Learning Java

Microsoft PowerPoint - ch6 [相容模式]

D C 93 2

<4D F736F F F696E74202D20332D322E432B2BC3E6CFF2B6D4CFF3B3CCD0F2C9E8BCC6A1AAD6D8D4D8A1A2BCCCB3D0A1A2B6E0CCACBACDBEDBBACF2E707074>

c_cpp

Wy159.mps

Chapter 9: Objects and Classes

EJB-Programming-4-cn.doc

<4D F736F F F696E74202D20C8EDBCFEBCDCB9B9CAA6D1D0D0DEBDB2D7F92E707074>

Microsoft PowerPoint - plan06.ppt

2/80 2

6-1 Table Column Data Type Row Record 1. DBMS 2. DBMS MySQL Microsoft Access SQL Server Oracle 3. ODBC SQL 1. Structured Query Language 2. IBM

untitled

詞 彙 表 編 號 詞 彙 描 述 1 預 約 人 資 料 中 文 姓 名 英 文 姓 名 身 份 證 字 號 預 約 人 電 話 性 別 2 付 款 資 料 信 用 卡 別 信 用 卡 號 信 用 卡 有 效 日 期 3 住 房 條 件 入 住 日 期 退 房 日 期 人 數 房 間 數 量 入

提问袁小兵:

untitled

Microsoft Word - 桂政发(2016)20号.doc


1.3

FY.DOC

untitled

Java 1 Java String Date

untitled

Java

Microsoft Word cppFinalSolution.doc

XML XML XMPP XML XML Schema XML XML,,, XML,

豐佳燕.PDF

國立屏東師範學院國民教育研究所碩士論文

第七讲 继承与多态

新版 明解C++入門編

Microsoft PowerPoint - ARC110_栾跃.ppt

OOP with Java 通知 Project 4: 4 月 18 日晚 9 点 关于抄袭 没有分数

obj-c_4.key

Microsoft PowerPoint - Aqua-Sim.pptx


封面.PDF

2 SGML, XML Document Traditional WYSIWYG Document Content Presentation Content Presentation Structure Structure? XML/SGML 3 2 SGML SGML Standard Gener

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

C C C The Most Beautiful Language and Most Dangerous Language in the Programming World! C 2 C C C 4 C Project 30 C Project 3 60 Project 40

IoC容器和Dependency Injection模式.doc

Thesis for the Master degree in Engineering Research on Negative Pressure Wave Simulation and Signal Processing of Fluid-Conveying Pipeline Leak Candi

软 件 工 程 专 业 习 指 南 目 录 一 软 件 工 程 专 业 设 置 背 景 与 发 展 前 景... 3 二 软 件 工 程 专 业 实 践 教 条 件... 4 三 软 件 工 程 专 业 课 程 类 型 及 核 方 式 软 件 工 程 专 业 课 程 类 型...7

Microsoft PowerPoint - 数据通信-ch1.ppt

Microsoft Word htm

Microsoft Word htm

_汪_文前新ok[3.1].doc

06-4.indd

JBuilder Weblogic

Scott Effective C++ C++ C++ Roger Orr OR/2 ISO C++ Effective Modern C++ C++ C++ Scoot 42 Bart Vandewoestyne C++ C++ Scott Effective Modern C++ Damien

无类继承.key

Microsoft Word - 01.DOC

(TestFailure) JUnit Framework AssertionFailedError JUnit Composite TestSuite Test TestSuite run() run() JUnit

概述

Microsoft Word - 3D手册2.doc

(Geographic data or geodata ) 30 (Buelher, K and L. Mckee1996) (Open GIS Consortium OGC) OGC GIS Open GIS OGC (Geography Markup Langu

CH01.indd

声 明 本 公 司 及 全 体 董 事 监 事 高 级 管 理 人 员 承 诺 不 存 在 虚 假 记 载 误 导 性 陈 述 或 重 大 遗 漏, 并 对 其 真 实 性 准 确 性 完 整 性 承 担 个 别 和 连 带 的 法 律 责 任 本 公 司 负 责 人 和 主 管 会 计 工 作 的

(Microsoft PowerPoint - UML\302\262\244\266_use case.ppt)

第 15 章 程 式 編 写 語 言 15.1 程 式 編 写 語 言 的 角 色 程 式 編 寫 語 言 是 程 式 編 寫 員 與 電 腦 溝 通 的 界 面 語 法 是 一 組 規 則 讓 程 式 編 寫 員 將 字 詞 集 合 起 來 電 腦 是 處 理 位 元 和 字 節 的 機 器, 與

<4D F736F F D D DBACEC0F25FD0A3B6D4B8E55F2DB6FED0A32D2D2DC8A5B5F4CDBCD6D0B5C4BBD8B3B5B7FBBAC52E646F63>

Chapter 1 What is Programing Paradigm 1

untitled

13 A DSS B DSS C DSS D DSS A. B. C. CPU D. 15 A B Cache C Cache D L0 L1 L2 Cache 16 SMP A B. C D 17 A B. C D A B - C - D

Microsoft Word 軟體設計第二部份範例試題_C++_ _1_.doc

9, : Java 19., [4 ]. 3 Apla2Java Apla PAR,Apla2Java Apla Java.,Apla,,, 1. 1 Apla Apla A[J ] Get elem (set A) A J A B Intersection(set A,set B) A B A B

Microsoft PowerPoint - OPVB1基本VB.ppt

RunPC2_.doc

概述

基于CDIO一体化理念的课程教学大纲设计


声 明 本 人 郑 重 声 明 : 此 处 所 提 交 的 硕 士 学 位 论 文 基 于 等 级 工 鉴 定 的 远 程 考 试 系 统 客 户 端 开 发 与 实 现, 是 本 人 在 中 国 科 学 技 术 大 学 攻 读 硕 士 学 位 期 间, 在 导 师 指 导 下 进 行 的 研 究

C/C++程序设计 - 字符串与格式化输入/输出

第3章.doc

Chapter12 Derived Classes

OOP with Java 通知 Project 4: 4 月 19 日晚 9 点

Chapter 9: Objects and Classes

untitled

第7章-并行计算.ppt

TCP/IP TCP/IP OSI IP TCP IP IP TCP/IP TCP/IP

全国计算机技术与软件专业技术资格(水平)考试

mvc


416 Journal of Software 4(3) 2003,1. Java, Java, Java : ; ; ;Java : TP311 : A (binding time analysis ), (partial evaluation)., [1~3]., C Java, Java.,.

OOP with Java 通知 Project 3: 3 月 29 日晚 9 点 4 月 1 日上课

Microsoft PowerPoint ARIS_Platform_en.ppt

内 容 简 介 本 书 是 一 本 关 于 语 言 程 序 设 计 的 教 材, 涵 盖 了 语 言 的 基 本 语 法 和 编 程 技 术, 其 中 包 含 了 作 者 对 语 言 多 年 开 发 经 验 的 总 结, 目 的 是 让 初 学 的 读 者 感 受 到 语 言 的 魅 力, 并 掌

2001 5,,, :,,?, 70 40?,,,, ;1 6,, 35 %,,500 ;,,, 200,,,,,,,,,, 3,,,,,,, 4, : ;; ;,,,,,,, 5,, 3 :,,1996,8 4 : :, ,,?,,:?? 4


W. Richard Stevens UNIX Sockets API echo Sockets TCP OOB IO C struct C/C++ UNIX fork() select(2)/poll(2)/epoll(4) IO IO CPU 100% libevent UNIX CPU IO

Transcription:

Essential Object-Oriented Programming Josh Ko 2007.03.11 object-oriented programming C++ Java OO class object OOP Ruby duck typing complexity abstraction paradigm objects objects model object-oriented decomposition algorithmic decomposition Booch 1 1 [Booch94] sec. 1.3, Algorithmic versus Object-Oriented Decomposition, p. 17. 1

Booch Data Abstraction public instance methods 2 interface 3 public instance methods signatures implementation abstract design by contract Andrew Koenig 4 Abstraction is selective ignorance. data abstraction C Stroustrup 5 supports enables 2 C++ public non-static member functions 3 interface Java interface Java 4 [Koenig97]. 5 [Stroustrup91] sec. 2 Programming Paradigms, par. 2. 2

Fortran C Modula-2 data abstraction data abstraction encapsulation data abstraction access control public members private members decoupling Interface Object Object Interface User User Implementation Implementation Design by Contract Bertrand Meyer design by contract DBC DBC Meyer 3

signature Arnold Gosling Holmes 6 class class print object print() process interval prioritize nonterminals signature Java documentation comments class class invariant state instance variables C++ class Stack template <typename T> class Stack { public: // interface // copy-control members omitted void push(const T&); void pop(); T& top() const; size_t size() const; bool empty() const; private: // implementation T* buf; size_t buf_size; size_t cur_size; void grow(); }; Stack objects class invariants 1. cur_size buf_size 6 [Arnold05], chap. 2 Classes and Objects, par. 3, p. 41. 4

2. buf[0] buf[cur_size 1] stack class invariants Stack objects valid state member functions precondition postcondition Class invariants class invariants class invariants private grow Stack class invariants grow class invariants class invariants class invariants class invariants class invariants class invariants member variables C++ std::pair std::pair member variables first second invariants class invariants class invariants class invariants constructor design by contract class invariants class invariants C++ Friend C++ friend functions friend functions member functions 7 class namespace friend functions class Sutter C++ Argument-Dependent Lookup ADL Koenig Lookup 8 ADL overload resolution name lookup namespace(s) 7 [Meyers00] 8 [Sutter00], Name Lookup, Namespaces, and the Interface Principle. 5

friend functions member functions namespace namespace friend functions abuse Abstract vs. Concrete data abstraction data abstraction data abstraction object-orientation C++ STL C++ data abstraction generic programming C++ OOP Data abstraction abstract data types ADT Doug McIlroy Those types are not abstract, they are as real as int and float. real concrete abstract concrete data abstraction Concrete types Stroustrup ADT 9 concrete types abstract classes class hierarchies int char object-oriented programming C++ data abstraction operator overloading concrete types concrete type int concrete types concrete objects int representation Data abstraction OOP runtime polymorphism 9 [Stroustrup00], sec. 10.1, p. 224, par. 2; sec. 10.3.4 The Significance of Concrete Class, p. 241. 6

ADT abstract data abstraction ADT Koenig inheritance program by difference data abstraction ADT ADT ADT superclass ADT subclass C++ base class derived class name hiding derived class base class derived class A subclass object = a superclass (sub)object + subclass extension. subclass superclass subclass object superclass object derived object base object base class private derived object superclass superclass C++/Java protected derived class base class derived class derived class base class base class derived class entities 10 C++ by value derived object base class variable slicing derived object base object base pointer/reference derived object base (sub)object pointer/reference base class 10 C++ friend functions friend functions object 7

declared type object actual type declared type actual type data abstraction OOP ADT GoF OO 11 Program to an interface, not an implementation. data abstraction ADT subclass ADT superclass superclass superclass superclass subclass objects subclass superclass IsA class Rectangle class Shape Liskov Substitution Principle LSP 12 superclass objects subclass objects substitutable Liskov S o 1 T o 2 T P o 1 o 2 P S T subtype data abstraction class class superclass superclass object subclass object 11 [Gamma95], sec. 1.6, Programming to an Interface, not an Implementation, p. 17. 12 [Martin02], chap. 10, LSP: The Liskov Substitution Principle. 8

LSP Actual Type Superclass Interface (substitutable) Subclass Object User Message Reference Type static binding superclass superclass object dynamic binding late binding virtual binding Java instance methods C++ virtual actual type reference type class class superclass superclass subclass subclass overrides superclass OOP polymorphism 13 Bertrand Meyer Open-Closed Principle OCP 14 Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification. superclass subclass GoF OCP 13 OOP 14 [Meyer97]; [Martin02], chap. 9, OCP: The Open-Closed Principle. 9

ADT ADT ADT program to an implementation 15 OCP LSP subclass object superclass object subclass object superclass subclass object application framework subclasses reuse reinvent the wheel DBC LSP Design by Contract LSP DBC subclass LSP subclass superclass Subclass superclass subclass superclass 16 subclass Java overriding method overridden method overridden method public overriding method protected subclasses Java/C++ covariant return types overriding method overridden method subtype supertype subtype LSP Abstract Classes & Java Interfaces Abstract class abstract class instantiated subclass 15 ADT 16 subclass subclass subclass 10

Java interface Java interface Java class C++ class 17 Java class Java interface members public static non-blank final Arnold Gosling Holmes class abstract interface class Java interface Java class interface C++ multiple inheritance C++ class base class Java class extension single inheritance interfaces class superclasses interfaces actual type 1. 2. 3. data abstraction 4. ADT ADT 5. OOP 17 Java interface C++ pure virtual functions abstract class 11

Thirddawn [Arnold05] Arnold, K., Gosling, J., Holmes, D. The Java Programming Language. Fourth edition, Addison-Wesley, 2005. [Booch94] Booch, G. Object-Oriented Analysis and Design with Applications. Second edition, Addison-Wesley, 1994. [Gamma95] Gamma, E., Helm, R., Johnson, R., Vlissides, J. Design Patterns. Addison-Wesley, 1995. [Koenig97] Koenig, A., Moo, B. E. Ruminations on C++. Addison-Wesley, 1997. [Martin02] Martin, R. C. Agile Software Development: Principles, Patterns, and Practices. Prentice Hall, 2002. [Meyer97] Meyer, B. Object-Oriented Software Construction. Second edition, Prentice Hall, 1997. [Meyers00] Meyers, S. How Non-Member Functions Improve Encapsulation. C/C++ Users Journal, February 2000. [Stroustrup91] Stroustrup, B. What is Object-Oriented Programming? (1991 revised version). Proc. 1st European Software Festival. February, 1991. [Stroustrup00] Stroustrup, B. The C++ Programming Language. Special third edition, Addison-Wesley, 2000. [Sutter00] Sutter, H. Exceptional C++. Addison-Wesley, 2000. 12