I’m writing some code that does a few different mathematical
calculations, then returns a value. All the calculations use the
same inputs, so there’s the potential for a lot of reuse here.
So, I’m looking for the pattern that fits what I need. The Command Pattern
seems very close to what I want, except execute() doesn’t return a
value. In fact, this description
of the Command Pattern uses it to implement a calculator, but it just
prints the results to the console instead of returning the value.
In order for me to use the Command Pattern, I’d have to change the
interface of the Command interface
either to add a getter for the value or add a return type for the
So, I need something almost, but not quite, exactly like the Command
Pattern. How have people implemented this in the past? I
feel there has to be another pattern out there for this, because it seems so common.