模板模式

2020-05-20  本文已影响0人  simplerandom
public abstract class Temple {
    public void one() {
        System.out.println("one");
    }

    public abstract void two();

    public void three() {
        System.out.println("three");
    }

    public void four() {
        System.out.println("four");
    }

    public final void begin() {
        one();
        two();
        three();
        four();
    }
}
public class Concrete extends Temple {
    @Override
    public void two() {
        System.out.println("concrete two方法");
    }
}

测试

public class Test {
    public static void main(String[] args) {
        new Concrete().begin();
    }
}
上一篇下一篇

猜你喜欢

热点阅读