Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Design Patterns with C++

You're reading from   Hands-On Design Patterns with C++ Solve common C++ problems with modern design patterns and build robust applications

Arrow left icon
Product type Paperback
Published in Jul 2023
Publisher Packt
ISBN-13 9781804611555
Length 626 pages
Edition 2nd Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Fedor G. Pikus Fedor G. Pikus
Author Profile Icon Fedor G. Pikus
Fedor G. Pikus
Arrow right icon
View More author details
Toc

Table of Contents (26) Chapters Close

Preface 1. Part 1: Getting Started with C++ Features and Concepts
2. Chapter 1: An Introduction to Inheritance and Polymorphism FREE CHAPTER 3. Chapter 2: Class and Function Templates 4. Chapter 3: Memory and Ownership 5. Part 2: Common C++ Idioms
6. Chapter 4: Swap – from Simple to Subtle 7. Chapter 5: A Comprehensive Look at RAII 8. Chapter 6: Understanding Type Erasure 9. Chapter 7: SFINAE, Concepts, and Overload Resolution Management 10. Part 3: C++ Design Patterns
11. Chapter 8: The Curiously Recurring Template Pattern 12. Chapter 9: Named Arguments, Method Chaining, and the Builder Pattern 13. Chapter 10: Local Buffer Optimization 14. Chapter 11: ScopeGuard 15. Chapter 12: Friend Factory 16. Chapter 13: Virtual Constructors and Factories 17. Chapter 14: The Template Method Pattern and the Non-Virtual Idiom 18. Part 4: Advanced C++ Design Patterns
19. Chapter 15: Policy-Based Design 20. Chapter 16: Adapters and Decorators 21. Chapter 17: The Visitor Pattern and Multiple Dispatch 22. Chapter 18: Patterns for Concurrency 23. Assessments 24. Index 25. Other Books You May Enjoy

What this book covers

Chapter 1, An Introduction to Inheritance and Polymorphism, provides a brief overview of the object-oriented features of C++. This chapter is not intended as a reference for object-oriented programming in C++, but, rather, highlights the aspects of it that are important for the subsequent chapters.

Chapter 2, Class and Function Templates, provides an overview of the generic programming facilities of C++—class templates, function templates, and lambda expressions. This chapter covers template instantiations and specializations, along with template function argument deduction and overload resolution, and prepares you for more complex uses of templates in later chapters.

Chapter 3, Memory and Ownership, describes modern idiomatic ways of expressing different kinds of memory ownership in C++. This is a collection of conventions or idioms—the compiler does not enforce these rules, but programmers will find it easier to understand each other if they use the shared idiomatic vocabulary.

Chapter 4, Swap - From Simple to Subtle, explores one of the most basic C++ operations, the swap, or exchange, of two values. This operation has surprisingly complex interactions with other C++ features that are discussed in the chapter.

Chapter 5, A Comprehensive Look at RAII, explores in detail one of the fundamental concepts of C++, that of resource management, and introduces what may be the most popular C++ idiom, RAII, which is the standard C++ approach to managing resources.

Chapter 6, Understanding Type Erasure, provides insight into a C++ technique that has been available in C++ for a long time but has grown in popularity and importance since the introduction of C++11. Type erasure allows the programmer to write abstract programs that do not explicitly mention certain types.

Chapter 7, SFINAE, Concepts, and Overload Resolution Management, discusses SFINAE—a C++ idiom that is, on the one hand, essential to the use of templates in C++ and just happens transparently, while on the other hand, requires a very thorough and subtle understanding of C++ templates when used purposefully.

Chapter 8, The Curiously Recurring Template Pattern, describes a mind-wrapping template-based pattern that combines the benefits of object-oriented programming with the flexibility of templates. The chapter explains the pattern and teaches you how to use it properly to solve practical problems. Lastly, this chapter prepares you for recognizing this pattern in later chapters.

Chapter 9, Named Arguments, Method Chaining, and the Builder Pattern, covers an unusual technique for calling functions in C++, using named arguments instead of positional ones. This is another one of those idioms we use implicitly in every C++ program, but its explicit purposeful use takes some thought.

Chapter 10, Local Buffer Optimization, is the only purely performance-oriented chapter in this book. Performance and efficiency are critical considerations that influence every design decision that affects the language itself—there is not a feature in the language that was not reviewed from the point of view of efficiency before being accepted into the standard. It is only fair that a chapter is dedicated to a common idiom used to improve the performance of C++ programs.

Chapter 11, ScopeGuard, introduces an old C++ pattern that has changed almost beyond recognition with the recent versions of C++. The chapter teaches you about a pattern for easily writing exception-safe, or, more generally, error-safe code in C++.

Chapter 12, Friend Factory, describes another old pattern that finds new uses in modern C++. This pattern is used to generate functions associated with templates, such as arithmetic operators for every type generated by a template.

Chapter 13, Virtual Constructors and Factories, covers another classic object-oriented programming pattern as applied to C++, the Factory pattern. In the process, the chapter also shows you how to get the appearance of polymorphic behavior from C++ constructors, even though constructors cannot be virtual.

Chapter 14, The Template Method Pattern and the Non-Virtual Idiom, describes an interesting crossover between a classic object-oriented pattern, the template, and a very C++-centric idiom. Together, they form a pattern that describes the optimal use of virtual functions in C++.

Chapter 15, Policy-Based Design, covers one of the jewels of C++ design patterns, the Policy pattern (more commonly known as the Strategy pattern), applied at compile time, that is, as a generic programming pattern instead of an object-oriented pattern.

Chapter 16, Adapters and Decorators, discusses the two very broad and closely related patterns as they apply to C++. The chapter considers the use of these patterns in object-oriented designs, as well as in generic programs.

Chapter 17, The Visitor Pattern and Multiple Dispatch, rounds off our gallery of classic object-oriented programming patterns with the perennially popular Visitor pattern. The chapter explains the pattern itself, then focuses on the ways that modern C++ makes the implementation of Visitor simpler, more robust, and less error-prone.

Chapter 18, Patterns for Concurrency, is a new addition to the book. While C++ has been used to write concurrent programs long before C++11 gave us the “official” tools for it, the wide range of problem-specific solutions makes identifying common patterns difficult. This chapter introduces the patterns that became the basic building blocks for designing concurrent software in C++.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image