Design mode Template

zhaozj2021-02-16  50

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

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.

转载请注明原文地址:https://www.9cbs.com/read-20606.html

New Post(0)