Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Created January 30, 2014 15:59
Show Gist options
  • Save trikitrok/8b4c7a1533e71c895a9d to your computer and use it in GitHub Desktop.
Save trikitrok/8b4c7a1533e71c895a9d to your computer and use it in GitHub Desktop.
Showing the strategy pattern at work
#include "Duck.h"
#include "QuackBehaviors/Quack.h"
#include "QuackBehaviors/Squeak.h"
#include "QuackBehaviors/MuteQuack.h"
int main(int argc, const char **argv) {
Duck duck(new Quack);
duck.quack();
duck.changeHowToQuack(new Squeak);
duck.quack();
duck.changeHowToQuack(new MuteQuack);
duck.quack();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment