设计模式-模板模式

1.public interface TestTemplate {

Response doSomeThing();

}
2.

`public abstract class SayHelloAb implements TestTemplate {
    @Override
    public Response doSomeThing() {
        log.info("Hello");
        doAnother();
        return null;
    }


    protected abstract Response doAnother();
}`
  1. ctrl+o 重写父类方法
public class DoSayHello extends SayHelloAb{

    @Override
    public Response doSomeThing() {
        return super.doSomeThing();
    }

    @Override
    protected Response doAnother() {
        log.info("another hello");
        return null;
    }
}
 @Autowired
    TestTemplate doSayHello;
    @Test
    public void testModel(){
        doSayHello.doSomeThing();
    }

[main] INFO c.b.t.s.s.s.testTemp.SayHelloAb:11 - Hello
[main] INFO c.b.t.s.s.s.testTemp.DoSayHello:19 - another hello

上一篇:工厂方法和抽象工厂模式


下一篇:详解ES6(四)-函数名与参数