go-pattern-examples/behavior/05_template_method/template_method_test.go

28 lines
445 B
Go
Raw Normal View History

2020-04-21 17:50:21 +03:00
package templatemethod
2020-05-03 16:08:56 +03:00
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}
2020-04-21 17:50:21 +03:00
2020-05-03 16:08:56 +03:00
aprinter.Set("---Paper--")
//打印
aprinter.DoPrintWork()
2020-04-21 17:50:21 +03:00
}