Template Template Mode Definition: Define the skeleton of an operation algorithm to delay some steps to its subclass.
When using Java abstract classes, the template mode is often used, so the template mode is commonly used. And it is easy to understand and use.
Public Abstract Class Benchmark {/ ** * The following is we hope to complete * / public abstract void benchmark (); / ** * Repeat Benchmark * / public final long repeat (int count) {ix <= 0) return 0; else {long startTime = System.currentTimeMillis (); for (int i = 0; i In the above example, we want to repeat the Benchmark () operation, but there is no description of the specific content of Benchmark (), but is delayed into its subclass: Public class method {/ ** * Really defined Benchmark content * / public void benchmark () {for (int i = 0; i At this point, the Template mode has been completed, is it simple? We call the REPEAT method as a template method, which is implemented in the subclass MethodBenchmark, which is delayed. See how to use: Benchmark Operation = new methodbenchmark (); long duration = Operation.repeat (Integer.Parseint (args [0] .trim ())); System.out.Println ("The Operation TOOK" Duration "MilliseConds"); Maybe you have used what is the use of abstract classes, now you should completely understand it? As for the benefits of this, it is obvious, the extension is strong, and the Benchmark content changes, I will do it again, don't have to be Modify other application code.