add example of state pattern in C++
This commit is contained in:
31
cpp/patterns/state/main.cpp
Normal file
31
cpp/patterns/state/main.cpp
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user