Review first the abstract base classes of all strategies (in this case, math operators):
MathOperator.h
This defines that any operator can perform its work by having its execute method called passing in an OperandStack. An operand stack is a regular stack that:
Returns 0 if it is empty
Is as big as memory allows.
Here is an example of a concrete implementation, a factorial method:
Factorial.cpp
Here are the tests that verify it works as expected(using CppUTest):
FactorialTest.cpp
In the next section, Template Method Pattern Example, each of the subclasses are all examples of the strategy as well.
Comments