标签:image 模板方法 结构 做什么 图片 子类 final 钩子方法 crete

public abstract class Game {
public final void play() {
init();
start();
if (hook()) {
end();
}
saowei();//钩子方法,基类空实现,子类视情况决定是否实现
}
private void saowei() {
}
protected abstract void init();
protected abstract void start();
protected abstract void end();
protected boolean hook() {
return true;
}
}
public class AGame extends Game {
@Override
protected void init() {
System.out.println("AGame::init()");
}
@Override
protected void start() {
System.out.println("AGame::start()");
}
@Override
protected void end() {
System.out.println("AGame::end()");
}
@Override
protected boolean hook() {
System.out.println("not execute AGame::end()");
return false;
}
}
标签:image 模板方法 结构 做什么 图片 子类 final 钩子方法 crete
原文地址:https://www.cnblogs.com/endian11/p/9146383.html