add example of state pattern in C++

This commit is contained in:
2021-05-11 18:53:16 -04:00
parent d7a25a0efc
commit 1c78867d91
6 changed files with 212 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
#include <iostream>
#include "state.hpp"
int main(const int argc, const char * argv[]) {
Car * testCar = new Car;
testCar->report();
// Test transition from Stopped->Running
testCar->Start();
testCar->report();
// Test transition from Running->Stopped
testCar->Stop();
testCar->report();
// Test transition from Stopped->Broken
testCar->Smash();
testCar->report();
std::cout << "\nTesting burning state...\n";
Car *newCar = new Car;
newCar->report();
// Test transition from Stopped->Running->Burning
newCar->Start();
newCar->Smash();
newCar->report();
}