Design mode Template

xiaoxiao2021-03-06  77

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

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.

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

New Post(0)