package com.bdqn.template; public abstract class BankTemplateMethod { //具体方法 public void takeNumber(){ System.out.println("取号排队"); } //帮里具体的业务 钩子方法 public abstract void transact(); public void ecaluate(){ System.out.println("反馈评分"); } public final void process(){ this.takeNumber(); this.transact(); this.ecaluate(); } }
package com.bdqn.template; public class Client { public static void main(String[] args) { BankTemplateMethod srt=new DrawMoney(); //取钱 srt.process(); //采用匿名内部类存钱 BankTemplateMethod strs=new BankTemplateMethod() { @Override public void transact() { System.out.println("我要存钱"); } }; strs.process(); } } class DrawMoney extends BankTemplateMethod{ @Override public void transact() { System.out.println("我要取钱"); } }