标签:设计 public eth sys protected app nal over out
父类编写算法结构码,子类实现逻辑细节;
public class TemplateMethod {
public final void print(String message) {
System.out.println("##########");
wrapPrint(message);
System.out.println("##########");
}
protected void wrapPrint(String message) {
}
public static void main(String[] args) {
TemplateMethod tm1 = new TemplateMethod(){
@Override
protected void wrapPrint(String message) {
System.out.println("#"+message+"#");
}
};
TemplateMethod tm2 = new TemplateMethod(){
@Override
protected void wrapPrint(String message) {
System.out.println("*"+message+"*");
}
};
tm1.print("Hello Thread");
tm2.print("Hello Thread");
}
}
标签:设计 public eth sys protected app nal over out
原文地址:https://www.cnblogs.com/luohoufa/p/10140971.html