API Design for C++
Contents
Author biography
xi
Foreword
xiii
Preface
xv
Acknowledgments
xxi
1. Introduction
1
What are APIs?
1
What’s different about API design?
4
Why should you use APIs?
7
When should you avoid APIs?
11
API examples
13
Libraries, frameworks, and software development kits
17
File formats and network protocols
19
About this book
21
2. Qualities
25
Model the problem domain
25
Hide implementation details
31
Minimally complete
42
Easy to use
50
Loosely coupled
65
Stable, documented, and tested
80
3. Patterns
81
Pimpl idiom
83
Singleton
93
Factory Methods
101
API wrapping patterns
107
Observer pattern
115
4. Design
123
A case for good design
123
Gathering functional requirements
129
Creating use cases
132
Elements of API design
139
Architecture design
142
Class design
154
Function design
167
5. Styles
179
Flat C APIs
180
Object-oriented C++ APIs
186
Template-based APIs
189
Functional APIs
193
Data-driven APIs
197
6. C++ usage
209
Namespaces
209
Constructors and assignment
211
Const correctness
216
Templates
220
Operator overloading
227
Function parameters
236
Avoid #define for constants
239
Avoid using friends
242
Exporting symbols
244
Coding conventions
247
7. C++ revisions
251
Which C++ revision to use
251
C++11 API features
252
C++14 API features
283
C++17 API features
289
C++20 API features
307
C++23 API features
322
8. Performance
329
Pass input arguments by const reference
331
Minimize #include dependencies
333
Declaring constants
338
Initialization lists
341
Memory optimization
343
Don’t inline functions until you need to
348
Copy on write
351
Iterating over elements
356
Performance analysis
360
9. Concurrency
367
Multithreading with C++
367
Terminology
369
Accessing shared data
373
Concurrent API design
378
10. Versioning
383
Version numbers
383
Software branching strategies
388
Life cycle of an API
392
Levels of compatibility
393
How to maintain backward compatibility
401
API reviews
408
11. Documentation
415
Reasons to write documentation
415
Types of documentation
423
Documentation usability
430
Using Doxygen
434
12. Testing
443
Reasons to write tests
443
Types of API testing
446
Writing good tests
454
Writing testable code
459
Automated testing tools
476
13. Objective-C and Swift
487
Interface design in C++ and Objective-C
487
Data hiding in Objective-C
489
Objective-C behind a C++ API
491
C++ behind an Objective-C API
494
C++ behind a Swift API
497
14. Scripting
501
Adding script bindings
501
Script binding technologies
506
Adding Python bindings with Boost Python
510
Adding Ruby bindings with SWIG
521
15. Extensibility
533
Extending via plugins
533
Extending via inheritance
549
Extending via templates
560
Appendix A: Libraries
565
References
583
Index
589
Buy The Book On
Buy It on Amazon
Buy It On Elsevier

© 2024 Martin Reddy, All Rights Reserved