The Decorator Pattern: The Full Code
The complete Decorator Pattern project, browsable file by file, organized the same way it would actually sit in a real codebase.
September 11, 20264 min read10 / 19
The last two posts built the decorator pattern piece by piece. This post is the reference: the whole project, as real files in real folders.
main.cpp
#include <iostream>
#include "coffee/Espresso.h"
#include "coffee/Caramel.h"
#include "coffee/Soy.h"
int main() {
Espresso espresso;
Caramel caramel(&espresso);
Soy soy(&caramel);
std::cout << "Espresso: " << espresso.cost() << "\n";
std::cout << "Espresso + Caramel: " << caramel.cost() << "\n";
std::cout << "Espresso + Caramel + Soy: " << soy.cost() << "\n";
return 0;
}Run this yourself: This exact file layout lives in the code-practice repo. Clone it,
cd into whichever language folder, and build it the same way as the other labs in this series.Keep reading