万本电子书0元读

万本电子书0元读

顶部广告

Hands-On Design Patterns with C++电子书

售       价:¥

18人正在读 | 1人评论 6.2

作       者:Fedor G. Pikus

出  版  社:Packt Publishing

出版时间:2019-01-30

字       数:77.6万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(1条)
  • 读书简介
  • 目录
  • 累计评论(1条)
A comprehensive guide with extensive coverage on concepts such as OOP, functional programming, generic programming, and STL along with the latest features of C++ Key Features * Delve into the core patterns and components of C++ in order to master application design * Learn tricks, techniques, and best practices to solve common design and architectural challenges * Understand the limitation imposed by C++ and how to solve them using design patterns Book Description C++ is a general-purpose programming language designed with the goals of efficiency, performance, and flexibility in mind. Design patterns are commonly accepted solutions to well-recognized design problems. In essence, they are a library of reusable components, only for software architecture, and not for a concrete implementation. The focus of this book is on the design patterns that naturally lend themselves to the needs of a C++ programmer, and on the patterns that uniquely benefit from the features of C++, in particular, the generic programming. Armed with the knowledge of these patterns, you will spend less time searching for a solution to a common problem and be familiar with the solutions developed from experience, as well as their advantages and drawbacks. The other use of design patterns is as a concise and an efficient way to communicate. A pattern is a familiar and instantly recognizable solution to specific problem; through its use, sometimes with a single line of code, we can convey a considerable amount of information. The code conveys: "This is the problem we are facing, these are additional considerations that are most important in our case; hence, the following well-known solution was chosen." By the end of this book, you will have gained a comprehensive understanding of design patterns to create robust, reusable, and maintainable code. What you will learn * Recognize the most common design patterns used in C++ * Understand how to use C++ generic programming to solve common design problems * Explore the most powerful C++ idioms, their strengths, and drawbacks * Rediscover how to use popular C++ idioms with generic programming * Understand the impact of design patterns on the program’s performance Who this book is for This book is for experienced C++ developers and programmers who wish to learn about software design patterns and principles and apply them to create robust, reusable, and easily maintainable apps.
目录展开

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

累计评论(1条) 1个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部