0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Template Method Pattern

Last updated at Posted at 2020-11-08

#Template Method Pattern
templateで処理の大枠を決めてロジックを共有する
サブクラスではtemplateで決た枠に従い処理を行う

Design Pattarm MENU

##Template Method Pattern 例
以下のクラス構成で確認します

クラス 説明
template.class 処理の大枠を記述する
sam1.class 処理の詳細を肉づける
sam2.class 処理の詳細を肉づける
user(Main.class) Template Patternの動作を確認する
*user 他の開発者がこのパターンを利用する、という意味合いを含みます
template.class
abstract class template{
  abstract String temp1();
  abstract String temp2();
  abstract String temp3();
  final    void show(){
           System.out.print(temp1()+temp2()+temp3()+"\n");
           }
}
sam1.class
class sam1 extends template{
  String temp1(){return "<<< ";}
  String temp2(){return "Template";}
  String temp3(){return " >>>";}
}
sam2.class
class sam2 extends template{
  String temp1(){return "[[[ ";}
  String temp2(){return "Template";}
  String temp3(){return " ]]]";}
}
user(Main.class)
public static void main(String[] args){
sam1 s1= new sam1();
sam2 s2= new sam2();
s1.show();
s2.show();
}}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?