From df100d6237134f9c30b8d5069fcf3e76f37a4deb Mon Sep 17 00:00:00 2001 From: bingor Date: Wed, 19 Oct 2022 09:52:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9D=A6=E5=85=8B=E5=A4=A7=E6=88=98=EF=BC=88?= =?UTF-8?q?=E4=B8=80=E6=9C=9F=EF=BC=89-=E8=AE=BE=E8=AE=A1=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F-templateMethod?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/msb/templateMethod/Main.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/main/java/com/msb/templateMethod/Main.java diff --git a/src/main/java/com/msb/templateMethod/Main.java b/src/main/java/com/msb/templateMethod/Main.java new file mode 100644 index 0000000..670bd6e --- /dev/null +++ b/src/main/java/com/msb/templateMethod/Main.java @@ -0,0 +1,43 @@ +package com.msb.templateMethod;/** + * @Author bingor + * @Date 2022/10/19 9:47 + * @Description: com.msb.templateMethod + * @Version: 1.0 + */ + +/** + *@ClassName Main + *@Description TODO + *@Author bingor + *@Date 2022/10/19 9:47 + *@Version 3.0 + */ +public class Main { + public static void main(String[] args) { + Father father = new Child(); + father.exe(); + } +} + +abstract class Father { + public void exe() { + opt1(); + opt2(); + } + + public abstract void opt1(); + public abstract void opt2(); +} + +class Child extends Father { + + @Override + public void opt1() { + System.out.println("child:opt1"); + } + + @Override + public void opt2() { + System.out.println("child:opt2"); + } +}