Author(s): Andrew Koenig, Barbara E. Moo
Publisher: Addison-Wesley
Year: 1997
Language: English
Commentary: this one's in English!
Pages: 395
Copyright
@=10
Contents xi
Preface Vll
@=16
0 Prelude 1
. 0.1 First try 1
. 0.2 Doing it without classes 4
. 0.3 Why was it easier in C++? 5
. 0.4 A bigger example 6
. 0.5 Conclusion 6
Part I Motivation 9
@>
1 Why I use C++ 11
. 1.1 The problem 11
. 1.2 History and context 12
. 1.3 Automatic software distribution 12
. 1.4 Enter C++ 15
. 1.5 Recycled software 20
. 1.6 Postscript 21
2 Why I work on C++ 23
. 2.1 The success of small projects 23
. 2.2 Abstraction 25
. 2.3 Machines should work for people 28
3 Living in the real world 29
@<
Part II Classes and inheritance 35
@>
4 Checklist for class authors 37
5 Surrogate classes 47
. 5.1 The problem 47
. 5.2 The classical solution 48
. 5.3 Virtual copy functions 49
. 5.4 Defining a surrogate class 50
. 5.5 Summary 53
6 Handles: Part 1 55
. 6.1 The problem 55
. 6.2 A simple class 56
. 6.3 Attaching a handle 58
. 6.4 Getting at the object 58
. 6.5 Simple implementation 59
. 6.6 Use-counted handles 60
. 6.7 Copy on write 62
. 6.8 Discussion 63
7 Handles: Part 2 67
. 7.1 Review 68
. 7.2 Separating the use count 69
. 7.3 Abstraction of use counts 70
. 7.4 Access functions and copy on write 73
. 7.5 Discussion 73
8 An object-oriented program 75
. 8.1 The problem 75
. 8.2 An object-oriented solution 76
. 8.3 Handle classes 79
. 8.4 Extension 1: New operations 82
. 8.5 Extension 2: New node types 85
. 8.6 Reflections 86
9 Analysis of a classroom exercise: Part 1 89
. 9.1 The problem 89
. 9.2 Designing the interface 91
. 9.3 A few loose ends 93
. 9.4 Testing the interface 94
. 9.5 Strategy 95
. 9.6 Tactics 96
. 9.7 Combining pictures 99
. 9.8 Conclusion 102
10 Analysis of a classroom exercise: Part 2 103
. 10.1 Strategy 103
. 10.2 Exploiting the structure 116
. 10.3 Conclusion 119
11 When not to use virtual functions 121
. 11.1 The case for 121
. 11.2 The case against 122
. 11.3 Destructors are special 127
. 11.4 Summary 129
.
@<
Part III Templates 131
@>
12 Designing a container class 133
. 12.1 What does it contain? 133
. 12.2 What does copying the container mean? 134
. 12.3 How do you get at container elements? 137
. 12.4 How do you distinguish reading from writing? 138
. 12.5 How do you handle container growth? 139
. 12.6 What operations does the container provide? 141
. 12.7 What do you assume about the container element type? 141
. 12.8 Containers and inheritance 143
. 12.9 Designing an array like class 144
13 Accessing container elements 151
. 13.1 Imitating a pointer 151
. 13.2 Getting at the data 153
. 13.3 Remaining problems 155
. 13.4 Pointer to const Array 159
. 13.5 Useful additions 161
14 Iterators 167
. 14.1 Completing the Pointer class 167
. 14.2 What is an iterator? 170
. 14.3 Deleting an element 171
. 14.4 Deleting the container 172
. 14.5 Other design considerations 173
. 14.6 Discussion 174
15 Sequences 175
. 15.1 The state of the art 175
. 15.2 A radical old idea 176
. 15.3 Well, maybe a few extras... 181
. 15.4 Example of use 184
. 15.5 Maybe a few more... 188
. 15.6 Food for thought 190
16 Templates as interfaces 191
. 16.1 The problem 191
. 16.2 The first example 192
. 16.3 Separating the iteration 192
. 16.4 Iterating over arbitrary types 195
. 16.5 Adding other types 196
. 16.6 Abstracting the storage technique 196
. 16.7 The proof of the pudding 199
. 16.8 Summary 200
17 Templates and generic algorithms 203
. 17.1 A specific example 204
. 17.2 Generalizing the element type 205
. 17.3 Postponing the count 205
. 17.4 Address independence 207
. 17.5 Searching a nonarray 208
. 17.6 Discussion 210
18 Generic iterators 213
. 18.1 A different algorithm 213
. 18.2 Categories of requirements 215
. 18.3 Input iterators 216
. 18.4 Output iterators 216
. 18.5 Forward iterators 217
. 18.6 Bidirectional iterators 218
. 18.7 Random-access iterators 218
. 18.8 Inheritance? 220
. 18.9 Performance 220
. 18.10 Summary 221
19 Using generic iterators 223
. 19.1 I tera tor types 224
. 19.2 Virtual sequences 224
. 19.3 An output-stream iterator 227
. 19.4 An input-stream iterator 229
. 19.5 Discussion 232
20 Iterator adaptors 233
. 20.1 An example 233
. 20.2 Directional asymmetry 235
. 20.3 Consistency and asymmetry 236
. 20.4 Automatic reversal 237
. 20.5 Discussion 240
21 Function objects 241
. 21.1 An example 241
. 21.2 Function pointers 244
. 21.3 Function objects 246
. 21.4 Function-object templates 248
. 21.5 Hiding intermediate types 249
. 21.6 One type covers many 250
. 21.7 Implementation 251
. 21.8 Discussion 253
22 Function adaptors 255
. 22.1 Why function objects? 255
. 22.2 Function objects for built-in operators 256
. 22.3 Binders 257
. 22.4 A closer look 258
. 22.5 Interface inheritance 259
. 22.6 U sing these classes 260
. 22.7 Discussion 261
.
@<
Part IV Libraries 263
@>
23 Libraries in everyday use 265
. 23.1 The problem 265
. 23.2 Understanding the problem-part 1 267
. 23.3 Implementation-part 1 267
. 23.4 Understanding the problem-part 2 270
. 23.5 Implementation-part 2 270
. 23.6 Discussion 272
24 An object lesson in library-interface design 275
. 24.1 Complications 276
. 24.2 Improving the interface 277
. 24.3 Taking stock 279
. 24.4 Writing the code 280
. 24.5 Conclusion 282
25 Library design is language design 283
. 25.1 Character strings 283
. 25.2 Memory exhaustion 284
. 25.3 Copying 287
. 25.4 Hiding the implementation 290
. 25.5 Default constructor 292
. 25.6 Other operations 293
. 25.7 Substrings 295
. 25.8 Conclusion 296
26 Language design is library design 297
. 26.1 Abstract data types 297
. 26.2 Libraries and abstract data types 299
. 26.3 Memory allocation 302
. 26.4 Memberwise assignment and initialization 303
. 26.5 Exception handling 305
. 26.6 Summary 306
.
@<
Part V Technique 307
@>
27 Classes that keep track of themselves 309
. 27.1 Design of a trace class 309
. 27.2 Creating dead code 312
. 27.3 Generating audit trails for objects 313
. 27.4 Verifying container behavior 315
. 27.5 Summary 320
28 Allocating objects in clusters 321
. 28.1 The problem 321
. 28.2 Designing the solution 321
. 28.3 Implementation 324
. 28.4 Enter inheritance 326
. 28.5 Summary 327
29 Applicators, manipulators, and function objects 329
. 29.1 The problem 329
. 29.2 A solution 332
. 29.3 A different solution 332
. 29.4 Multiple arguments 334
. 29.5 An example 335
. 29.6 Abbreviations 337
. 29.7 Musings 338
. 29.8 Historical notes, references, and acknowledgments 339
30 Decoupling application libraries from input-output 341
. 30.1 The problem 341
. 30.2 Solution 1: Trickery and brute force 342
. 30.3 Solution 2: Abstract output 343
. 30.4 Solution 3: Trickery without brute force 345
. 30.5 Remarks 348
.
@<
Part VI Wrapup 349
@>
31 Simplicity through complexity 351
. 31.1 The world is complicated 351
. 31.2 Complexity becomes hidden 352
. 31.3 Computers are no different 353
. 31.4 Computers solve real problems 354
. 31.5 Class libraries and language semantics 355
. 31.6 Making things easy is hard 357
. 31.7 Abstraction and interface 357
. 31.8 Conservation of complexity 358
32 What do you do after you say Bello world? 361
. 32.1 Find the local experts 361
. 32.2 Pick a tool kit and become comfortable with it 362
. 32.3 Some parts of C are essential... 362
. 32.4 ...but others are not 364
. 32.5 Set yourself a series of problems 366
. 32.6 Conclusion 368
.
@<
Index 371