Skip to Content
C++ Software Design
book

C++ Software Design

by Klaus Iglberger
September 2022
Intermediate to advanced content levelIntermediate to advanced
438 pages
10h 45m
English
O'Reilly Media, Inc.
Book available
Content preview from C++ Software Design

Chapter 4. The Visitor Design Pattern

This entire chapter is focused on the Visitor design pattern. If you’ve already heard about the Visitor design pattern or even used it in your own designs, you might be wondering why I have chosen Visitor as the first design pattern to explain in detail. Yes, Visitor is definitely not one of the most glamorous design patterns. However, it will definitely serve as a great example to demonstrate the many options you have when implementing a design pattern and how different these implementations can be. It will also serve as an effective example of advertising the advantages of modern C++.

In “Guideline 15: Design for the Addition of Types or Operations, we first talk about the fundamental design decision you’ll need to make when walking in the realm of dynamic polymorphism: focus on either types or operations. In that guideline, we will also talk about the intrinsic strengths and weaknesses of programming paradigms.

In “Guideline 16: Use Visitor to Extend Operations”, I will introduce you to the Visitor design pattern. I will explain its intent to extend operations instead of types, and show you both the advantages and the shortcomings of the classic Visitor pattern.

In “Guideline 17: Consider std::variant for Implementing Visitor, you will make the acquaintance of the modern implementation of the Visitor design pattern. I will introduce you to std::variant and explain the many advantages of that particular implementation.

In “Guideline 18: ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Effective Modern C++

Effective Modern C++

Scott Meyers

Publisher Resources

ISBN: 9781098113155Errata PageSupplemental Content