Design Patterns

  4 minute read


Design Patterns - With World of Warcraft examples

I have been wanting to refresh my memory of classic design patterns (gang of four) and i had some free time at hand. So i decided to read them again and code some samples of my own. While at it, i thought why not give a ride to some recent c++ features, visual studio code and cmake too ? If you add being one of the oldschool world of warcraft players on top of having time and ambition, it was clear what i was going to do and this small piece of code happened.

If you wish to learn about design patterns, there are far simpler, cleaner and straightforward examples out there on the internet. This is not one of those. What i did here is using a lot of world of warcraft metaphors for implementing design patterns. I implemented these patterns just for having a bit of fun and for no serious purpose but if someone reads and enjoys them too, suit yourselves.


  • Every design pattern tells a story about how (part of) World of Warcraft game could be explained.
  • There are three main categories of patterns. Creational, Structural and Behavioral.
  • Every individual pattern is listed under the related category.
  • No file in any pattern has external dependencies. Patterns don’t try to reuse each others code. You can just cut a folder and it should work alone.
  • Every individual pattern has its own namespace.
  • Every design patter has [PatternName]Test.h and [PatternName]Test.cpp files with only one void [PatternName]Test() function in it. [PatternName]Test.h files are included in parent directory Testers.h, which is included in main.cpp
  • There are three libraries, one for each pattern category. I opted to create objects for each pattern and then combining these objects in their related category library.
  • I used a lazy version of hungarian notation.
  • I tried to keep names of the files, variables, class names and functions clear.
  • Except a few, every class has its own file.


  • CMake
  • Any modern C++ (14) compiler. No external dependencies or libraries.


I started with Visual Studio 2017 and then switched to Visual Studio Code 1.16. Since Visual Studio now supports CMake, it should compile this out of the box. For VS Code, you need to setup extensions and json files.

To work with Visual Studio Code


Make sure these are setup properly

  • Create a c_cpp_properties.json file with appropriate include paths.
  • Setup a launch.json file like provided in .vscode directory.
  • settings.json and .cmaketools.json should get automatically created.

Running the tests

Root directory contains a main.cpp file. Just uncomment the related line to test the pattern.

Source Code

Source on Github


This project is licensed under the MIT License




  • Implemented the following patterns
    • Behavioral
      • Chain Of Responsibility
      • Command
      • Interpreter
      • Iterator
      • Mediator
      • Memento
      • Observer
      • State
      • Strategy
      • Template Method
      • Visitor
    • Structural
      • Adapter
      • Bridge
      • Composite
      • Decorator
      • Facade
      • Flyweight
      • Proxy
    • Creational
      • Builder
      • Factory
      • Prototype
      • Singleton

To Do

  • Add Concurrency Patterns
  • Add Architectural Patterns
  • Add Uncategorized Patterns


Chain of Responsibility

Various parties with different weaknesses enter a dungeon with multiple bosses. Each boss can wipe a certain party.


Player decides to modify his new armor pieces with various options of different professions.


A translator learns various kalimdor languages and uses them to translate.


Raid leader checks out every single player in the raid.


The raid engages in fight. Raid leader tells everyone what to do when an event occurs.


Transmogrifier screen.


Boss fight ensues and Deadly Boss Mods notifies everyone when events happen.


Warrior stance dance.


How different classes kill mobs.

Template Method

Similar and differentiating things while leveling professions.


Players visit fruit and armor vendors.


You think only healers can heal ? Rogue’s can heal too.


How Druids, Monks and Paladins fullfill all three roles.


Parties and raids are both player groups. Raids can also be defined with multiple parties.


An armor piece can be modified to have multiple properties.


Would be nice if a giant macro button could kill every boss.


When a new character is created, it has the base same base stats with all other new characters of the same race.


Stopcasting healing macro button replaces normal healing button.


A spawn point which builds various classes.


Client asks “looking for group tool” to create a party for them. Client can ask for a stealth or a plate team.


Client asks “looking for group” tool for a copy of a player class.


Druid is the ultimate answer to all questions.


World of Warcraft, Warcraft and Blizzard Entertainment are trademarks or registered trademarks of Blizzard Entertainment, Inc. in the U.S. and/or other countries.

Based on patterns in the book; “Design Patterns: Elements of Reusable Object-Oriented Software Book by Erich Gamma, John Vlissides, Ralph Johnson, and Richard Helm”