This repository contains a selection of examples from the Head First Design Patterns, 2nd Edition book, rewritten in C++. The code is primarily for my own learning and deepening of my knowledge of design patterns, and is not intended to serve as a complete conversion of the Java source code in the book (which can be found on the official website). I have made an effort to leverage modern C++ features, such as using smart pointers instead of traditional raw pointers. The source files were created using the VSCode editor.
This repository follows the structure of the Head First Design Patterns book. The examples are organized to mirror the chapters and patterns presented in the book, making it easy to navigate through the different design patterns covered. Each folder typically corresponds to a chapter from the book, and inside you’ll find the C++ implementation of the respective design pattern.
To get started with the examples in this repository, you can clone it using the following command:
git clone https://github.com/BeagleBasset/Head-First-Design-Patterns-CPP.git
Once you have cloned the repository, you can open the individual files in a C++ IDE or editor such as VSCode or CLion, and start exploring the code.
If you want to compile and run the examples locally, you can use the following steps:
-
Navigate to the folder containing the example you wish to compile.
-
If you have the g++ compiler installed, use the following command to compile the code:
g++ -std=c++17 -o main *.cpp
-
After compilation, run the program using:
./main
This will compile and execute the C++ examples. You can also use other C++ compilers. Just ensure they support the C++17 standard and modify the command accordingly to fit your compiler.
If you would like to contribute to this project by adding more examples or improving existing ones, feel free to fork the repository and submit a pull request. All contributions are welcome!