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