Skip to content

Instantly share code, notes, and snippets.

@zz22394
Created November 13, 2017 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zz22394/1e5a097253db10f606dbbed8075c00f5 to your computer and use it in GitHub Desktop.
Save zz22394/1e5a097253db10f606dbbed8075c00f5 to your computer and use it in GitHub Desktop.
public abstract class AbstractClass
{
public abstract void method1();
public abstract void method2();
public void method3() {
// do Something
}
public void templateMethod() {
// 実装はSubClussに任せる
method1();
method2();
// 既に実装した
method3();
}
}
public class ConcreteClassA extends AbstractClass
{
public void method1() {
System.out.println("method 1 in ConcreteClassA");
}
public void method2() {
System.out.println("method 2 in ConcreteClassA");
// 下記のように、method3をコールすることは避けるべき
//method3();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment