售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
Title Page
Copyright and Credits
Hands-On Design Patterns with C++
About Packt
Why subscribe?
Packt.com
Contributors
About the author
About the reviewer
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Conventions used
Get in touch
Reviews
An Introduction to Inheritance and Polymorphism
Classes and objects
Inheritance and class hierarchies
Polymorphism and virtual functions
Multiple inheritance
Summary
Questions
Further reading
Class and Function Templates
Templates in C++
Function templates
Class templates
Variable template
Non-type template parameters
Template instantiations
Function templates
Class templates
Template specializations
Explicit specialization
Partial specialization
Template function overloading
Variadic templates
Lambda expressions
Summary
Questions
Further reading
Memory Ownership
Technical requirements
What is memory ownership?
Well-designed memory ownership
Poorly designed memory ownership
Expressing memory ownership in C++
Expressing non-ownership
Expressing exclusive ownership
Expressing transfer of exclusive ownership
Expressing shared ownership
Summary
Questions
Further reading
Swap - From Simple to Subtle
Technical requirements
Swap and the standard template library
Swap and STL containers
Non-member swap
Swapping like the standard
When and why to use swap
Swap and exception safety
Other common swap idioms
How to implement and use swap correctly
Implementing swap
Using swap correctly
Summary
Questions
A Comprehensive Look at RAII
Technical requirements
Resource management in C++
Installing the microbenchmark library
Installing Google Test
Counting resources
Dangers of manual resource management
Manual resource management is error-prone
Resource management and exception safety
The RAII idiom
RAII in a nutshell
RAII for other resources
Releasing early
Careful implementation of Resource Acquisition is Initialization objects
Downsides of RAII
Summary
Questions
Further reading
Understanding Type Erasure
Technical requirements
What is type erasure?
Type erasure by example
How is type erasure implemented in C++?
Very old type erasure
Object-oriented type erasure
The opposite of the type erasure
Type erasure in C++
When to use type erasure, and when to avoid it
Type erasure and software design
Installing the micro-benchmark library
The overhead of type erasure
Summary
Questions
SFINAE and Overload Resolution Management
Technical requirements
Overload resolution and overload sets
C++ function overloading
Template functions
Type substitution in template functions
Type deduction and substitution
Substitution failure
Substitution Failure Is Not An Error
Taking control of overload resolution
Basic SFINAE
Advanced SFINAE
Advanced SFINAE revisited
The ultimate SFINAE
Summary
Questions
Further reading
The Curiously Recurring Template Pattern
Technical requirements
Wrapping your head around CRTP
What is wrong with a virtual function?
Introducing CRTP
CRTP and static polymorphism
Compile-time polymorphism
The compile-time pure virtual function
Destructors and polymorphic deletion
CRTP and access control
CRTP as a delegation pattern
Expanding the interface
Summary
Questions
Named Arguments and Method Chaining
Technical requirements
The problem with arguments
What's wrong with many arguments
Aggregate parameters
Named arguments in C++
Method chaining
Method chaining and named arguments
Performance of the named arguments idiom
General method chaining
Method chaining versus method cascading
General method chaining
Method chaining in class hierarchies
Summary
Questions
Local Buffer Optimization
Technical requirements
The overhead of small memory allocations
The cost of memory allocations
Introducing local buffer optimization
The main idea
Effect of local buffer optimization
Additional optimizations
Local buffer optimization beyond strings
Small vector
Type-erased and callable objects
Local buffer optimization in the C++ library
Downsides of local buffer optimization
Summary
Questions
Further reading
ScopeGuard
Technical requirements
Error handling and Resource Acquisition Is Initialization
Error safety and exception safety
Resource Acquisition Is Initialization
The ScopeGuard pattern
ScopeGuard basics
Generic ScopeGuard
ScopeGuard and exceptions
What must not throw an exception
Exception-driven ScopeGuard
Type-erased ScopeGuard
Summary
Questions
Friend Factory
Technical requirements
Friends in C++
How to grant friendship in C++
Friends versus member functions
Friends and templates
Friends of template classes
The template friend factory
Generating friends on demand
The friend factory and the Curiously Recurring Template Pattern
Summary
Questions
Virtual Constructors and Factories
Technical requirements
Why constructors cannot be virtual
When does an object get its type?
The Factory pattern
The basics of the Factory method
Arguments for factory methods
Dynamic type registry
Polymorphic factory
Factory-like patterns in C++
Polymorphic copy
CRTP Factory and return types
CRTP Factory with less copy-paste
Summary
Questions
The Template Method Pattern and the Non-Virtual Idiom
Technical requirements
The Template Method pattern
The Template Method in C++
Applications of the Template Method
Pre-and post-conditions and actions
The Non-Virtual Interface
Virtual functions and access
The NVI idiom in C++
A note about destructors
Drawbacks of the Non-Virtual Interface
Composability
The Fragile Base Class problem
Summary
Questions
Further reading
Singleton - A Classic OOP Pattern
Technical requirements
The singleton pattern – what is it and what is it for?
What is a singleton?
When to use the singleton
Types of singletons
Static singleton
Meyers' Singleton
Leaky singletons
Summary
Questions
Policy-Based Design
Technical requirements
Strategy pattern and policy-based design
Foundations of policy-based design
Implementation of policies
Use of policy objects
Advanced policy-based design
Policies for constructors
Policies for test
Policy adapters and aliases
Using policies to control the public interface
Rebinding policies
Recommendations and guidelines
Strengths of the policy-based design
Disadvantages of policy-based design
Guidelines for policy-based designs
Almost policy-based approach
Summary
Questions
Adapters and Decorators
Technical requirements
The decorator pattern
Basic decorator pattern
Decorators the C++ way
Polymorphic decorators and their limitations
Composable decorators
The Adapter pattern
Basic Adapter pattern
Function adapters
Compile-time adapters
Adapter versus policy
Summary
Questions
The Visitor Pattern and Multiple Dispatch
Technical requirements
The Visitor pattern
What is the Visitor pattern?
Basic Visitor in C++
Visitor generalizations and limitations
Visiting complex objects
Visiting composite objects
Serialization and deserialization with Visitor
Acyclic Visitor
Visitors in modern C++
Generic Visitor
Lambda Visitor
Generic Acyclic Visitor
Compile-time Visitor
Summary
Questions
Assessments
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
Chapter 9
Chapter 10
Chapter 11
Chapter 12
Chapter 13
Chapter 14
Chapter 15
Chapter 16
Chapter 17
Chapter 18
Other Books You May Enjoy
Leave a review - let other readers know what you think
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜