Hi
Below is a code for Strategy
pattern interface Strategy
{
void strategyMethod();
}
class Strategy1 implements Strategy
{
public void strategyMethod
(
//implementation of Strategy1
}
}
class Strategy2 implements Strategy
{
public void strategyMethod
(
//implementation of Strategy2
}
}
class Context
{
private Strategy strategy;
Strategy decide(int case)
{
switch (case)
case '1': return new Strategy1() break
case '2': return new Strategy1() break
}
}
Test {
public static void main(
String a[])
{
Context context = new Context();
int value = getStrategy();
Strategy strategy = context.decode(value);
strategy.strategyMethod()
}
}
Isn't this the case of a simple OO
polymorphism. what is the big deal abt having this as a named pattern? Isnt is so obvios? or am i missing something here?
And In case of template pattern, instead of interface we have an abstract class called Strategy. rest remains the same.
Is this the only difference between Strategy and Template pattern?