Created
May 11, 2011 07:02
-
-
Save anonymous/966026 to your computer and use it in GitHub Desktop.
StrategyパターンによるTemplate Methodパターンの書き換え
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ■Template Method Pattern | |
public abstract class Template { | |
public final void templateMethod() { | |
... | |
method1(); | |
... | |
method2(); | |
... | |
method3(); | |
... | |
} | |
protected void method1(); | |
protected void method2(); | |
protected void method3(); | |
} | |
public class Concrete1 extends Template { | |
@Override | |
protected void method1() { | |
... | |
} | |
@Override | |
protected void method2() { | |
... | |
} | |
@Override | |
protected void method3() { | |
... | |
} | |
} | |
// ■Strategy Pattern | |
public interface Strategy { | |
void method1(); | |
void method2(); | |
void method3(); | |
} | |
public class Client { | |
public void templateMethod(final Strategy strategy) { | |
... | |
strategy.method1(); | |
... | |
strategy.method2(); | |
... | |
strategy.method3(); | |
... | |
} | |
} | |
public class ConcreteStrategy implements Strategy { | |
public void method1() { | |
... | |
} | |
public void method2() { | |
... | |
} | |
public void method3() { | |
... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment