"Big Talk design mode" study Note 7: Template method mode

Source: Internet
Author: User

  

Sample Exam paper:

  

1. Test Paper Parent class:

     Public classTestpaper { Public voidTestQuestion1 () {Console.WriteLine ("What is Yang's character in the novel? A. Flying Fox biography B. Tianlong eight C. Hero of the shoot carving d. Laughing and Proud"); Console.WriteLine ("Answer:"+Answer1 ()); }         Public voidTestQuestion2 () {Console.WriteLine ("what is the character of the novel that makes Fox Rush? A. Flying Fox biography B. Tianlong eight C. Hero of the shoot carving d. Laughing and Proud"); Console.WriteLine ("Answer:"+Answer2 ()); }         Public Virtual stringAnswer1 () {return ""; }         Public Virtual stringAnswer2 () {return ""; }    }

2. Student a copy of the test paper category:

 public  class   Testpapera:testpaper { public  overri De  string   Answer1 () { Span style= "color: #0000ff;" >return   c   "         public  override  string   Answer2 () { return   "         ; }    }

3. Student B-Copy of the paper class:

    class Testpaperb:testpaper    {        publicoverridestring  Answer1 ()        {            return  "b";        }          Public Override string Answer2 ()        {            return"D";        }    }

4. Client code:

    classProgram {Static voidMain (string[] args) {Console.WriteLine ("students a copy of the test paper:"); Testpaper Studenta=NewTestpapera ();            Studenta.testquestion1 ();            Studenta.testquestion2 (); Console.WriteLine ("Student B-copy of the test paper:"); Testpaper STUDENTB=NewTestpaperb ();            Studentb.testquestion1 ();        Studentb.testquestion2 (); }    }

When we are going to complete a process or a series of steps that are consistent at a certain level of detail, but the implementation of individual steps at a more detailed level may not be the same, we usually consider using a template method pattern to handle it.

"Big Talk design mode" study Note 7: Template method mode

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.