模板方法模式

This commit is contained in:
刘洪宝
2018-12-01 12:09:22 +08:00
parent bcc666a0bb
commit 41aa89c062
3 changed files with 192 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
package main
import (
"fmt"
)
// 实现一个Base
type Base struct {
}
func (b *Base) Print() {
fmt.Println("这是base的print")
}
type Example struct {
Base
}
func (e Example) Print() {
fmt.Println("这是example的print")
}
func main() {
e := new(Example)
//e := Example{}
e.Print()
}