I. Demand analysis
The steps to solve a certain kind of thing are fixed, at which point we can provide a template code for this kind of thing, thereby increasing the efficiency
Second, the pattern design:
1. Write a solution to one thing in this category (including the template section and the change section)
2. Extract the changed parts into a method that describes them as abstract methods
3. Use final cosmetic template method to prevent being rewritten
Third, code implementation
Use a simple little example to illustrate: the execution time of the calculation program
3.1 Tool Code
Abstract class calruntime{
Public final void GetTime () {
Long starttime = System.currenttimemillis (); The time when the record started
Code ();
Long endtime = System.currenttimemillis (); The time at which the record ended.
System.out.println ("Running Time:" + (Endtime-starttime));
}
public abstract void Code ();
}
3.2 Test Code
Class Testcal extends Calruntime
{
public static void Main (string[] args)
& nbsp {
testcal testcal = new testcal ();
testcal.gettime ();
}
public Void Code () {
//your code
}