Part 1Principles of Object\|Oriented Programming
CHAPTER 1Introduction to Object\|Oriented Programming
1.1Object\|Oriented Thinking Methodology6
1.1.1Induction and Deduction6
1.1.2Composition and Decomposition7
1.1.3Object\|Orientation as a Thinking Methodology9
1.2Programming Techniques and Concepts11
1.2.1What is Programming?11
1.2.2Abstraction, Information Hiding and Modeling13
1.2.3Procedural Programming and Modules15
1.2.4Encapsulation18
1.2.5Abstract Data Type20
1.3Object\|Oriented Programming21
1.4Other Programming Paradigms24
1.4.1Imperative Programming25
1.4.2Functional Programming25
1.4.3Logic Programming26
1.4.4Relationships between Object\|Oriented Programming and Other
Paradigms27
1.5Object\|Oriented Languages28
1.5.1Simula 6728
1.5.2Smalltalk29
1.5.3C++30
1.5.4Java31
1.5.5C#32
1.5.6Others33
1.6Summary34
CHAPTER 2Object, Classes and Inheritance
2.1Object39
2.1.1Real\|World Object Properties39
2.1.2Virtual Objects41
2.1.3The External and Internal View of an Object42
2.1.4Definition of an Object43
Contents Object\|Oriented Programming in C++: A Project\|Based Approach 2.2Message43
2.2.1The Only Way to Interact43
2.2.2Definition of a Message44
2.2.3Message Categories45
2.2.4Objects in Programming45
2.3Encapsulation and Protocol45
2.4Class46
2.4.1Abstraction46
2.4.2Classification47
2.4.3The Basic View of a Class48
2.4.4Class Definition49
2.4.5Relationships among Classes50
2.4.6The Characteristics of a Class50
2.5Instantiation51
2.6Metaclass53
2.7Inheritance55
2.7.1The Properties of Inheritance55
2.7.2Inheritance Definition56
2.7.3Categories of Inheritance57
2.7.4Naming Conflicts58
2.7.5Precedence Conflicts59
2.8Superclass and Subclass60
2.8.1Subclassing60
2.8.2Modifiability61
2.9Abstract Class61
2.10Summary63
CHAPTER 3Polymorphism, Dynamic Binding, Overloading and
Other Concepts3.1Polymorphism69
3.1.1General Meanings of Polymorphism69
3.1.2Introduction of Polymorphism to Programming Languages70
3.1.3Categories of Polymorphism71
3.1.4The Drawbacks of Polymorphism73
3.2Overloading75
3.2.1Overloading Based on Scopes 75
3.2.2Overloading Based on Type Signatures76
3.3Static and Dynamic Binding77
3.4Overriding79
3.4.1Overriding Variables80
3.4.2Overriding Methods82
3.5Other Object\|Oriented Programming Concepts82
3.5.1Object Interactions83
3.5.2Design Patterns86
3.5.3Objects and Agents95
3.5.4Object\|Orientation and Reusable Components98
3.6Summary100
CHAPTER 4Object\|Oriented Design
4.1Object\|Oriented Software Engineering105
4.2Object\|Oriented Design108
4.2.1OOA vs. OOD108
4.2.2OOD Steps and Tasks110
4.2.3Discussions114
4.3Unified Modeling Language115
4.3.1Use Case Modeling and Use Case Diagrams115
4.3.2Class and Object Diagrams117
4.3.3Association Diagram118
4.3.4Dynamic Modeling121
4.3.5Other Diagrams122
4.4CASE Tools for Object\|Oriented Design123
4.4.1The Basic Architecture of OO ICASE Tools124
4.4.2Some ICASE Tools for OOA/OOD126
4.5Metrics of Object Systems128
4.5.1The Analysis for the Complexity of an Object System128
4.5.2Lorenz Metrics130
4.5.3The CK OO Metrics Suite132
4.5.4The Productivity Metrics of Object Systems134
4.6Summary135
Part 2Problem Solving with C++
CHAPTER 5Overview of the Basics of C++
5.1The Simplest C++ Program141
5.2Functions143
5.2.1Function Declaration and Definition143
5.2.2Parameters and Arguments144
5.2.3Constant Reference Parameter147
5.2.4Returned Values148
5.2.5Default Arguments148
5.2.6Viewing Functions as Objects149
5.3Fundamental Objects in C++150
5.3.1Basic Classes and Their Instances151
5.3.2Variable Declaration153
5.3.3Variable Scopes154
5.4Basic Streams for Input and Output156
5.4.1Output Stream156
5.4.2Input Stream157
5.5C++ Control Structures158
5.5.1Sequential Statements158
5.5.2Conditional Structures159
5.5.3Iterative Structures161
5.6Pointers and Memory Allocation165
5.6.1Pointers to Constants167
5.6.2Constant Pointers168
5.6.3Pointers and Arrays168
5.6.4Void Pointers170
5.6.5Allocating Memory172
5.6.6Functions Returning a Pointer175
5.7Summary177
CHAPTER 6Objects and Classes in C++
6.1Project Description181
6.2Analysis and Design182
6.3Class183
6.4Accessing Modifiers184
6.5Member Function Implementation186
6.6Constructors189
6.7Destructor190
6.8Enumeration191
6.9Switch/Case Structure and rand() Function193
6.10Basic Do\|Loop Structure197
6.11Instantiation and Messages198
6.12Standard Input and Output Streams200
6.13Deleting Objects201
6.14The Complete main() Function for the Project 202
6.15Object Copying204
6.16Summary207
CHAPTER 7Inheritance in C++
7.1Project Description211
7.2Analysis and Design212
7.3Base and Derived Classes215
7.3.1Static Variable217
7.4Overriding218
7.5Accessibility of Inherited Members219
7.6Constructor Initializer225
7.7Constructor and Destructor Execution Order226
7.8Creating Instances of Derived Classes227
7.9Create Report on Screen: More on Output Stream229
7.10Function main()232
7.11Running Result of Our Project234
7.12Multiple and Virtual Inheritance236
7.12.1Virtual Base Classes237
7.13Summary238
CHAPTER 8Polymorphism and Overloading in C++
8.1 Project Description: A Self\|Test Program243
8.2Analysis and Design244
8.3Abstract Classes and Virtual Functions247
8.4Derived Classes from an Abstract Class250
8.4.1Derived Abstract Class252
8.5The ExamPaper Class256
8.5.1Polymorphism and Dynamic Binding257
8.5.2Overloading Functions259
8.5.3Other Implementations259
8.6Function main()261
8.6.1Compatibility between Base and Derived Classes263
8.6.2The Main Loop of a Test266
8.6.3The Final Code of main()268
8.7Other Auxiliary Statements271
8.8Sample Running Results272
8.9Other C++ Concepts Relevant to Polymorphism275
8.9.1Polymorphism and Pointers275
8.9.2Virtual Destructors276
8.9.3“this” Pointer278
8.9.4Overloading Functions and Inheritance279
8.10Summary280
CHAPTER 9Templates, Exception Handling and Overloaded
Operators in C++9.1Project Description: A Dictionary Application285
9.2Analysis and Design287
9.3Templates288
9.4Exception Handling292
9.5Function main()298
9.6Auxiliary Statements and Running Results302
9.7Relevant Concepts with Templates305
9.7.1Class Templates and Classes305
9.7.2Function Templates306
9.7.3Overloaded Operators308
9.7.4Overloading a Function Template310
9.8Concepts Relevant with Exception Handling312
9.8.1Unwinding the Exception Stack312
9.8.2Exception with No Catch313
9.8.3Exception within an Exception314
9.8.4Exceptions in Templates316
9.8.5Grouping Exceptions317
9.8.6Re\|throwing an Exception318
9.8.7Exception Interface Specification319
9.9Summary320
CHAPTER 10Container Classes in C++
10.1Project Description: A Student Registration Program325
10.2Analysis and Design326
10.3Linked List327
10.3.1Simple Linked List328
10.3.2Doubly Linked List334
10.4Application of Simple List340
10.5Application of Doubly Linked List341
10.6An Auxiliary Class and Function main()346
10.7Compilation and Execution Results350
10.8Application of Doubly Linked List in a Polymorphic Way353
10.9Summary360
CHAPTER 11Streams and Friends in C++
11.1I/O Operators and Streams366
11.1.1Streams366
11.1.2Output of Basic Objects366
11.1.3Input of Basic Objects368
11.1.4The States of Streams370
11.1.5The Flags and Formats of Streams372
11.1.6Overloaded I/O Operators on Streams377
11.1.7Manipulators381
11.1.8File Streams386
11.1.9String Streams390
11.2Friend391
11.2.1Friend Functions392
11.2.2Friend Classes393
11.2.3Properties of Friends399
11.3Summary400
CHAPTER 12Use of the Standard Library of C++
12.1C++ STL405
12.1.1Containers and Algorithms406
12.1.2Iterators411
12.1.3Other Parts of the STL414
12.2List415
12.2.1The Interfaces of List416
12.2.2The Application of List416
12.2.3The Algorithm Library422
12.2.4Function Objects433
12.3Map434
12.3.1The Interfaces of Map and Pair435
12.3.2Application of Maps436
12.4String443
12.4.1The Interface of String443
12.4.2The Application of String445
12.5Summary448Index450References460 Part 1Principles of Object\|Oriented Programming
CHAPTER 1Introduction to Object\|Oriented Programming
1.1Object\|Oriented Thinking Methodology6
1.1.1Induction and Deduction6
1.1.2Composition and Decomposition7
1.1.3Object\|Orientation as a Thinking Methodology9
1.2Programming Techniques and Concepts11
1.2.1What is Programming?11
1.2.2Abstraction, Information Hiding and Modeling13
1.2.3Procedural Programming and Modules15
1.2.4Encapsulation18
1.2.5Abstract Data Type20
1.3Object\|Oriented Programming21
1.4Other Programming Paradigms24
1.4.1Imperative Programming25
1.4.2Functional Programming25
1.4.3Logic Programming26
1.4.4Relationships between Object\|Oriented Programming and Other
Paradigms27
1.5Object\|Oriented Languages28
1.5.1Simula 6728
1.5.2Smalltalk29
1.5.3C++30
1.5.4Java31
1.5.5C#32
1.5.6Others33
1.6Summary34
CHAPTER 2Object, Classes and Inheritance
2.1Object39
2.1.1Real\|World Object Properties39
2.1.2Virtual Objects41
2.1.3The External and Internal View of an Object42
2.1.4Definition of an Object43
Contents Object\|Oriented Programming in C++: A Project\|Based Approach 2.2Message43
2.2.1The Only Way to Interact43
2.2.2Definition of a Message44
2.2.3Message Categories45
2.2.4Objects in Programming45
2.3Encapsulation and Protocol45
2.4Class46
2.4.1Abstraction46
2.4.2Classification47
2.4.3The Basic View of a Class48
2.4.4Class Definition49
2.4.5Relationships among Classes50
2.4.6The Characteristics of a Class50
2.5Instantiation51
2.6Metaclass53
2.7Inheritance55
2.7.1The Properties of Inheritance55
2.7.2Inheritance Definition56
2.7.3Categories of Inheritance57
2.7.4Naming Conflicts58
2.7.5Precedence Conflicts59
2.8Superclass and Subclass60
2.8.1Subclassing60
2.8.2Modifiability61
2.9Abstract Class61
2.10Summary63
CHAPTER 3Polymorphism, Dynamic Binding, Overloading and
Other Concepts3.1Polymorphism69
3.1.1General Meanings of Polymorphism69
3.1.2Introduction of Polymorphism to Programming Languages70
3.1.3Categories of Polymorphism71
3.1.4The Drawbacks of Polymorphism73
3.2Overloading75
3.2.1Overloading Based on Scopes 75
3.2.2Overloading Based on Type Signatures76
3.3Static and Dynamic Binding77
3.4Overriding79
3.4.1Overriding Variables80
3.4.2Overriding Methods82
3.5Other Object\|Oriented Programming Concepts82
3.5.1Object Interactions83
3.5.2Design Patterns86
3.5.3Objects and Agents95
3.5.4Object\|Orientation and Reusable Components98
3.6Summary100
CHAPTER 4Object\|Oriented Design
4.1Object\|Oriented Software Engineering105
4.2Object\|Oriented Design108
4.2.1OOA vs. OOD108
4.2.2OOD Steps and Tasks110
4.2.3Discussions114
4.3Unified Modeling Language115
4.3.1Use Case Modeling and Use Case Diagrams115
4.3.2Class and Object Diagrams117
4.3.3Association Diagram118
4.3.4Dynamic Modeling121
4.3.5Other Diagrams122
4.4CASE Tools for Object\|Oriented Design123
4.4.1The Basic Architecture of OO ICASE Tools124
4.4.2Some ICASE Tools for OOA/OOD126
4.5Metrics of Object Systems128
4.5.1The Analysis for the Complexity of an Object System128
4.5.2Lorenz Metrics130
4.5.3The CK OO Metrics Suite132
4.5.4The Productivity Metrics of Object Systems134
4.6Summary135
Part 2Problem Solving with C++
CHAPTER 5Overview of the Basics of C++
5.1The Simplest C++ Program141
5.2Functions143
5.2.1Function Declaration and Definition143
5.2.2Parameters and Arguments144
5.2.3Constant Reference Parameter147
5.2.4Returned Values148
5.2.5Default Arguments148
5.2.6Viewing Functions as Objects149
5.3Fundamental Objects in C++150
5.3.1Basic Classes and Their Instances151
5.3.2Variable Declaration153
5.3.3Variable Scopes154
5.4Basic Streams for Input and Output156
5.4.1Output Stream156
5.4.2Input Stream157
5.5C++ Control Structures158
5.5.1Sequential Statements158
5.5.2Conditional Structures159
5.5.3Iterative Structures161
5.6Pointers and Memory Allocation165
5.6.1Pointers to Constants167
5.6.2Constant Pointers168
5.6.3Pointers and Arrays168
5.6.4Void Pointers170
5.6.5Allocating Memory172
5.6.6Functions Returning a Pointer175
5.7Summary177
CHAPTER 6Objects and Classes in C++
6.1Project Description181
6.2Analysis and Design182
6.3Class183
6.4Accessing Modifiers184
6.5Member Function Implementation186
6.6Constructors189
6.7Destructor190
6.8Enumeration191
6.9Switch/Case Structure and rand() Function193
6.10Basic Do\|Loop Structure197
6.11Instantiation and Messages198
6.12Standard Input and Output Streams200
6.13Deleting Objects201
6.14The Complete main() Function for the Project 202
6.15Object Copying204
6.16Summary207
CHAPTER 7Inheritance in C++
7.1Project Description211
7.2Analysis and Design212
7.3Base and Derived Classes215
7.3.1Static Variable217
7.4Overriding218
7.5Accessibility of Inherited Members219
7.6Constructor Initializer225
7.7Constructor and Destructor Execution Order226
7.8Creating Instances of Derived Classes227
7.9Create Report on Screen: More on Output Stream229
7.10Function main()232
7.11Running Result of Our Project234
7.12Multiple and Virtual Inheritance236
7.12.1Virtual Base Classes237
7.13Summary238
CHAPTER 8Polymorphism and Overloading in C++
8.1 Project Description: A Self\|Test Program243
8.2Analysis and Design244
8.3Abstract Classes and Virtual Functions247
8.4Derived Classes from an Abstract Class250
8.4.1Derived Abstract Class252
8.5The ExamPaper Class256
8.5.1Polymorphism and Dynamic Binding257
8.5.2Overloading Functions259
8.5.3Other Implementations259
8.6Function main()261
8.6.1Compatibility between Base and Derived Classes263
8.6.2The Main Loop of a Test266
8.6.3The Final Code of main()268
8.7Other Auxiliary Statements271
8.8Sample Running Results272
8.9Other C++ Concepts Relevant to Polymorphism275
8.9.1Polymorphism and Pointers275
8.9.2Virtual Destructors276
8.9.3“this” Pointer278
8.9.4Overloading Functions and Inheritance279
8.10Summary280
CHAPTER 9Templates, Exception Handling and Overloaded
Operators in C++9.1Project Description: A Dictionary Application285
9.2Analysis and Design287
9.3Templates288
9.4Exception Handling292
9.5Function main()298
9.6Auxiliary Statements and Running Results302
9.7Relevant Concepts with Templates305
9.7.1Class Templates and Classes305
9.7.2Function Templates306
9.7.3Overloaded Operators308
9.7.4Overloading a Function Template310
9.8Concepts Relevant with Exception Handling312
9.8.1Unwinding the Exception Stack312
9.8.2Exception with No Catch313
9.8.3Exception within an Exception314
9.8.4Exceptions in Templates316
9.8.5Grouping Exceptions317
9.8.6Re\|throwing an Exception318
9.8.7Exception Interface Specification319
9.9Summary320
CHAPTER 10Container Classes in C++
10.1Project Description: A Student Registration Program325
10.2Analysis and Design326
10.3Linked List327
10.3.1Simple Linked List328
10.3.2Doubly Linked List334
10.4Application of Simple List340
10.5Application of Doubly Linked List341
10.6An Auxiliary Class and Function main()346
10.7Compilation and Execution Results350
10.8Application of Doubly Linked List in a Polymorphic Way353
10.9Summary360
CHAPTER 11Streams and Friends in C++
11.1I/O Operators and Streams366
11.1.1Streams366
11.1.2Output of Basic Objects366
11.1.3Input of Basic Objects368
11.1.4The States of Streams370
11.1.5The Flags and Formats of Streams372
11.1.6Overloaded I/O Operators on Streams377
11.1.7Manipulators381
11.1.8File Streams386
11.1.9String Streams390
11.2Friend391
11.2.1Friend Functions392
11.2.2Friend Classes393
11.2.3Properties of Friends399
11.3Summary400
CHAPTER 12Use of the Standard Library of C++
12.1C++ STL405
12.1.1Containers and Algorithms406
12.1.2Iterators411
12.1.3Other Parts of the STL414
12.2List415
12.2.1The Interfaces of List416
12.2.2The Application of List416
12.2.3The Algorithm Library422
12.2.4Function Objects433
12.3Map434
12.3.1The Interfaces of Map and Pair435
12.3.2Application of Maps436
12.4String443
12.4.1The Interface of String443
12.4.2The Application of String445
12.5Summary448Index450References460