mirror of
https://github.com/crazybber/go-pattern-examples.git
synced 2024-11-25 21:26:03 +03:00
28 lines
445 B
Go
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()
|
|
|
|
}
|