關於 範本方法

關於 範本方法

關於 範本方法

關於 範本方法

class TestPaper {
public void TestQuestion1() { … Answer1(); }
public void TestQuestion2() { … Answer2(); }
public void TestQuestion3() { … Answer3(); }
protected virtual string Answer1();
protected virtual string Answer2();
protected virtual string Answer3();
}

class TestPaperA : TestPaper {

protected override string Answer1() {
return “b”;
}
protected override string Answer2() {
return “c”;
}
protected override string Answer3() {
return “a”;
}
}

class TestPaperB : TestPaper {

protected override string Answer1() {
return “c”;
}
protected override string Answer2() {
return “a”;
}
protected override string Answer3() {
return “a”;
}
}

static void Main(string[] args)
{
TestPaper studentA = new TestPaperA();
studentA.TestQuestion1();
studentA.TestQuestion2();
studentA.TestQuestion3();
TestPaper studentB = new TestPaperB();
studentB.TestQuestion1();
studentB.TestQuestion2();
studentB.TestQuestion3();

}