Add example of adapter pattern in C++

This commit is contained in:
2021-05-11 16:57:21 -04:00
parent da9d26cf15
commit 912cb47dcf
5 changed files with 83 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
#include <iostream>
#include "adapter.hpp"
int main(const int argc, const char * argv[]) {
const int a = 5;
const int b = 10;
std::cout << "A = " << a << "\nB = " << b << std::endl;
// Testing target implementation
Add adder;
std::cout << "Adding a + b: " << adder.doMath(a, b) << std::endl;
// Testing RandomAddAdapter using RandomNumber as the adaptee
RandomNumber *adaptee = new RandomNumber(100);
RandomAddAdapter *adapter = new RandomAddAdapter(adaptee);
std::cout << "\nAdding a + b + RandomNumber: " << adapter->doMath(a, b)
<< std::endl;
}