Template Definition: Define a skeleton of an operation algorithm to delay some steps to its subcategories.
In fact, Java's abstract category was originally Template mode, so it was very common. And it is easy to understand and use, we start directly:
Public Abstract Class Benchmark {/ ** * The following is 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 to its subcategory: 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? Take a look at 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 the abstract category, now you should completely understand? As for the benefits of doing this, it is obvious, the extension is strong, the Benchmark content changes, I just want to do a succession category, don't have to be Modify other application code.