Add example of bridge pattern in C++
This commit is contained in:
28
cpp/patterns/bridge/main.cpp
Normal file
28
cpp/patterns/bridge/main.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "abstraction.hpp"
|
||||
#include "implementation.hpp"
|
||||
|
||||
int main(const int argc, const char * argv[]) {
|
||||
Add *add = new Add;
|
||||
SimpleCalculator adder(add);
|
||||
const int a = 5;
|
||||
const int b = 10;
|
||||
std::cout << "A = " << a << "\nB = " << b << std::endl;
|
||||
|
||||
std::cout << "\nTesting " << adder.getName() << ".doMath(a, b)...\n";
|
||||
std::cout << "Result: " << adder.doMath(a, b);
|
||||
|
||||
auto *sub = new Subtract;
|
||||
SimpleCalculator subtractor(sub);
|
||||
std::cout << "\n\nTesting " << subtractor.getName() << ".doMath(a, b)...\n";
|
||||
std::cout << "Result: " << subtractor.doMath(a, b);
|
||||
|
||||
// Testing extension of abstraction
|
||||
std::cout << "\n\nTesting VerboseCalculator.doMath(a, b)...\n";
|
||||
VerboseCalculator verboseCalculator(add);
|
||||
verboseCalculator.doMath(a, b);
|
||||
}
|
||||
Reference in New Issue
Block a user