concept

A set of operational steps is defined in abstraction to form the algorithm framework, while some steps are deferred to subclasses. Typically, the same code is extracted into a parent class and its behavior is constrained by hook functions. The advantage is to extract common code, easy to maintain, the disadvantage is reduced readability.

implementation

public abstract class Template {
    protected void powerOn(){
        System.out.println("Open"):
    }
    protected void load(){
        System.out.println("loading"):
    }
    protected void login(){
        System.out.println("Login"):
    }

    public final void startUp(){
        powerOn();
        load();
        login();
    }
}

public class Computer1 extends Template {
    @Overrude
    public void login(){
        System.out.println("Secure Login"); 
    }
}

public class Computer2 extends Templete {
    @Override
    public void login(){
        super();
        System.out.println("Fingerprinting one more time."); }}Copy the code