Praise for C++ Software Design
Even after knowing design patterns for a long time, this book showed me a surprisingly large number of new aspects on how to use them properly in the context of C++ and the SOLID principles.
Matthias Drfel, CTO at INCHRON AG
I really enjoyed reading the book! Studying the guidelines made me reconsider my code and improve it by applying them. Can you ask for more?
Daniela Engert, senior software engineer at GMH Prftechnik GmbH
One of the most entertaining and useful software design books Ive read in a long while.
Patrice Roy, professeur, Collge Lionel-Groulx
It has been over 25 years since the Gang of Fours Design Patterns changed the way programmers think about software. This book changed the way I think about Design Patterns.
Stephan Weller, Siemens Digital Industries Software
C++ Software Design
by Klaus Iglberger
Copyright 2022 Klaus Iglberger. All rights reserved.
Printed in the United States of America.
Published by OReilly Media, Inc. , 1005 Gravenstein Highway North, Sebastopol, CA 95472.
OReilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com.
Acquisitions Editor: Amanda Quinn | Indexer: Judith McConville |
Development Editor: Shira Evans | Interior Designer: David Futato |
Production Editor: Kate Galloway | Cover Designer: Karen Montgomery |
Copyeditor: Sonia Saruba | Illustrator: Kate Dullea |
Proofreader: Piper Editorial Consulting, LLC |
- September 2022: First Edition
Revision History for the First Edition
- 2022-09-21: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781098113162 for release details.
The OReilly logo is a registered trademark of OReilly Media, Inc. C++ Software Design, the cover image, and related trade dress are trademarks of OReilly Media, Inc.
The views expressed in this work are those of the author and do not represent the publishers views. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
978-1-098-11316-2
[LSI]
Preface
In your hands youre holding the C++ book that I wish I wouldhave had many years ago. Not as one of my first books, no, but as an advanced book, after Ihad already digested the language mechanics and was able to think beyond the C++syntax. Yes, this book would have definitely helped me better understand the fundamentalaspects of maintainable software, and Im confident that it will help you too.
Why I Wrote This Book
By the time I was really digging into the language (that was a few years after the firstC++ standard had been released), I had read pretty much every C++ bookthere was. But despite the fact that many of these books were great and definitely paved theway for my current career as a C++ trainer and consultant, they were toofocused on the little details and the implementation specifics, and too far away from the biggerpicture of maintainable software.
At the time, very few books truly focused on the bigger picture, dealing with the development of large software systems. Among these were John Lakoss Large Scale C++ Software Design, Unfortunately, over the years, thissituation hasnt really changed: most books, talks, blogs, etc., primarily focus onlanguage mechanics and featuresthe small details and specifics. Very few, and in my opinionway too few, new releases focus on maintainable software, changeability, extensibility,and testability. And if they try to, they unfortunately quickly fall back into thecommon habit of explaining language mechanics and demonstrating features.
This is why Ive written this book. A book that does not, in contrast to most others,spend time on the mechanics or the many features of the language, but primarily focuses onchangeability, extensibility, and testability of software in general. A book that does notpretend that the use of new C++ standards or features will make the differencebetween good or bad software, but instead clearly shows that it is the management ofdependencies that is decisive, that the dependencies in our code decide between it beinggood or bad. As such, it is a rare kind of book in the world of C++ indeed, asit focuses on the bigger picture: software design.
What This Book Is About
Software Design
From my point of view, good software design is the essence of every successful softwareproject. Yet still, despite its fundamental role, there is so little literature on the topic,and very little advice on what to do and how to do things right. Why? Well, because itsdifficult. Very difficult. Probably the most difficult facet of writing software that wehave to face. And thats because there is no single right solution, no golden adviceto pass on through the generations of software developers. It always depends.
Despite this limitation, I will give advice on how to design good, high-qualitysoftware. I will provide design principles, design guidelines, and design patterns thatwill help you to better understand how to manage dependencies and turn your softwareinto something you can work with for decades. As stated before, there is no golden advice,and this book doesnt hold any ultimate or perfect solution. Instead, I try toshow the most fundamental aspects of good software, the most important details, the diversityand the pros and the cons of different designs. I will also formulate intrinsic design goalsand demonstrate how to achieve these goals with Modern C++.
Modern C++
For more than a decade, weve been celebrating the advent ofModern C++, applauding the many new features and extensions of the language, andby doing so, creating the impression that Modern C++ will help us solve allsoftware-related problems. Not so in this book. This book does not pretend thatthrowing a few smart pointers at the code will make the code Modern or automaticallyyield good design. Also, this book wont show Modern C++ as an assortmentof new features. Instead, it will show how the philosophy of the language has evolved andthe way we implement C++ solutions today.
But of course, we will also see code. Lots of it. And of course this book will make use of thefeatures of newer C++ standards (including C++20).However, it will also make an effort to emphasize that the design is independent ofthe implementation details and the used features. New features dont change the rules aboutwhat is good design or bad design; they merely change the way we implement good design. Theymake it easier to implement good design. So this book shows and discusses implementationdetails, but (hopefully) doesnt get lost in them and always remains focused on the bigpicture: software design and design patterns.