package org.example.template;publicclassTest{publicstaticvoidmain(String[] args){
Father father =newLilei();
father.life();
System.out.println("------------华丽的分割线----------------");
father =newHanmei();
father.life();}}
1.模板模式在父类中定义主体流程,封装公共方法,预留钩子方法,由继承的子类实现。2.创建抽象父类Fatherpackage org.example.template;public abstract class Father { //定义业务流程 public void life() { study(); work(); love(); } //公共方法 public void study() {