Template design Pattern

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.