Template Design Pattern Overview
The template method pattern is defined as the skeleton of an algorithm, and the specific algorithm is deferred to the subclass to realize
Advantages:
Using the template method pattern, the skeleton of the algorithm can be defined at the same time, it is very flexible to implement the concrete algorithm to meet the user's flexible needs.
Disadvantages:
If the algorithm skeleton is modified, the implementation class needs to be modified
PackageCom.model;ImportJava.io.BufferedInputStream;ImportJava.io.BufferedOutputStream;ImportJava.io.FileInputStream;ImportJava.io.FileOutputStream;Importjava.io.IOException; Public Abstract classGetTime { Public LongGetTime ()throwsioexception{Longstart=System.currenttimemillis ();//for (int i=0;i<10000;i++) {//System.out.println (i);// }//String str= "c:\\users\\administrator.pmimp83hwnikwov\\desktop\\" Bulk Download 27.02_ Reflection (Overview and classification of class loaders) \ \ \\Java video \ \java Basic \\day27\\avi\\27.01_ Reflection (class loading overview and Loading time). avi ";//bufferedoutputstream bos=new Bufferedoutputstream (New FileOutputStream ("Copy.avi"));//bufferedinputstream bis=new Bufferedinputstream (new FileInputStream (str));//byte[] bys=new byte[1024];//int len=0;//While ((Len=bis.read (bys))!=-1) {//bos.write (bys, 0, Len);// } //give me another test of an operation, a collection of frames, a multithreaded operation ...//we should learn to use the open and closed principle. So the content inside the test should be a block of code, a methodcode (); LongEnd=System.currenttimemillis (); returnend-start; } Public Abstract voidcode ();} PackageCom.model; Public classFordemoextendsgettime{@Override Public voidcode () { for(inti=0;i<10000;i++) {System.out.println (i); } }} PackageCom.model;Importjava.io.IOException; Public classGettimedemo { Public Static voidMain (string[] args)throwsIOException {//GetTime gt=new Fordemo ();GetTime gt=NewIodemo (); LongTime=Gt.gettime (); System.out.println ("Spend" +time+ "milliseconds"); }} PackageCom.model;ImportJava.io.BufferedInputStream;ImportJava.io.BufferedOutputStream;ImportJava.io.FileInputStream;ImportJava.io.FileOutputStream;Importjava.io.IOException; Public classIodemoextendsgettime{@Override Public voidcode () {String str= "c:\\users\\administrator.pmimp83hwnikwov\\desktop\\" Bulk Download "27.02_ Reflection (Overview and classification of class loaders) \ \ \\Java Video \\JAVA basic article \ \ Day27\\avi\\27.01_ Reflection (class loading overview and Loading time). avi "; Try{bufferedoutputstream Bos=NewBufferedoutputstream (NewFileOutputStream ("Copy.avi")); Bufferedinputstream bis=NewBufferedinputstream (NewFileInputStream (str)); byte[] bys=New byte[1024]; intLen=0; while((Len=bis.read (bys))!=-1) {bos.write (bys,0, Len); } bos.close (); Bis.close (); }Catch(IOException e) {e.printstacktrace (); } }}
Template design Pattern