go-pattern-examples/behavior/05_template_method/template_method_test.go
2020-05-03 21:08:56 +08:00

28 lines
445 B
Go

package templatemethod
import "testing"
func TestTemplateMethod(t *testing.T) {
//打印机
aprinter := Printer{}
//这个是被复合的work流程
aprinter.DoPrintWork()
//连接PDF打印机
aprinter.printer = &PDF{output: "./home"}
aprinter.Set("---PDF--")
//打印
aprinter.DoPrintWork()
//连接纸质打印机
aprinter.printer = &DevicePrinter{quality: 5}
aprinter.Set("---Paper--")
//打印
aprinter.DoPrintWork()
}