"OO tutorial using C C++ 001.ps.gz" - читать интересную книгу автора



Introduction to Object-Oriented Programming

Using C++

Peter M"uller [email protected] Globewide Network Academy (GNA)

www.gnacademy.org/

November 18, 1996

Contents 1 Introduction 1 2 A Survey of Programming Techniques 3

2.1 Unstructured Programming . . . . . . . . . . . . . . . . . . . . . . . 3 2.2 Procedural Programming . . . . . . . . . . . . . . . . . . . . . . . . 4 2.3 Modular Programming . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.4 An Example with Data Structures . . . . . . . . . . . . . . . . . . . 5

2.4.1 Handling Single Lists . . . . . . . . . . . . . . . . . . . . . . . 5 2.4.2 Handling Multiple Lists . . . . . . . . . . . . . . . . . . . . . 7 2.5 Modular Programming Problems . . . . . . . . . . . . . . . . . . . . 7

2.5.1 Explicit Creation and Destruction . . . . . . . . . . . . . . . 8 2.5.2 Decoupled Data and Operations . . . . . . . . . . . . . . . . 8 2.5.3 Missing Type Safety . . . . . . . . . . . . . . . . . . . . . . . 9 2.5.4 Strategies and Representation . . . . . . . . . . . . . . . . . . 9 2.6 Object-Oriented Programming . . . . . . . . . . . . . . . . . . . . . 10 2.7 Excercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

3 Abstract Data Types 13

3.1 Handling Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.2 Properties of Abstract Data Types . . . . . . . . . . . . . . . . . . . 14 3.3 Generic Abstract Data Types . . . . . . . . . . . . . . . . . . . . . . 16 3.4 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 3.5 Abstract Data Types and Object-Orientation . . . . . . . . . . . . . 18 3.6 Excercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

4 Object-Oriented Concepts 19

4.1 Implementation of Abstract Data Types . . . . . . . . . . . . . . . . 19 4.2 Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 4.3 Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 4.4 Message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 4.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 4.6 Excercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

5 More Object-Oriented Concepts 25

5.1 Relationships . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 5.2 Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 5.3 Multiple Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 5.4 Abstract Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 5.5 Excercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

i

ii CONTENTS 6 Even More Object-Oriented Concepts 35

6.1 Generic Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 6.2 Static and Dynamic Binding . . . . . . . . . . . . . . . . . . . . . . . 37 6.3 Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

7 Introduction to C++ 43