Yesterday, One of my coworkers presented an overview of the Strategy Pattern. There is already a lot about this (and other) patterns online, but I thought it might be useful (to me) to put up a “schematic” of the pattern for future reference:
interface IStrategicInterface { StrategicMethod(parms); } class SuperClass : IStrategicInterface { StrategicMethod strategicMemberFunction; } class SubClassA : Superclass or IStrategicInterface { public SubClassA(IStrategicInterface conretedStrategicMethod) { strategicMemberFunction = concretedStategicMethod; } } class SubClassB : Superclass or IStrategicInterface { public SubClassB(IStrategicInterface conretedStrategicMethod) { strategicMemberFunction = concretedStategicMethod; } } class ConcreteStrategy1 : IStrategicInterface { StrategicMethod(parms) {...1...} } class ConcreteStrategy2 : IStrategicInterface { StrategicMethod(parms) {...2...} }
Now objects of either subclass (SubClassA
or SubClassB
) can be constructed to accept either ConcreteStategy1
or ConcreteStrategy2
as the method they will use when the strategicMemberFunction()
is called.