大话设计模式(golang) 七、模版方法模式
模式特点:通过吧不变的行为搬到父类,去除子类中的重复代码。 程序实例:考试时使用同一种考卷(父类),不同学生上交自己填写的试卷(子类方法的实现) package main import ( "fmt" ) type TestPaper struct { child interface{} } func (t *TestPaper) testQuestion1() { fmt.Println("杨过得到,后来给了郭靖,练成倚天剑、屠龙刀的玄铁可能是[] a.球磨铸铁 b.马口铁 c.高速合金钥 d.碳素纤维") fmt.Println("答案:", t.child.(Answers).answer1()) } func (t *TestPaper) testQuestion2() { fmt....阅读全文