go-pattern-examples/behavior/07_visitor/visitor_test.go

34 lines
590 B
Go
Raw Normal View History

2020-04-21 17:50:21 +03:00
package visitor
2020-05-04 11:12:01 +03:00
import "testing"
func TestVisitor(t *testing.T) {
//汽油提供给,制衣工厂
g := gas{density: 100}
//柴油,提供给军工厂
d := diesel{energy: 897}
//购买石油的客户
m := &militaryFactory{}
c := &clothFactory{}
g.Accept(c)
d.Accept(m)
2020-04-21 17:50:21 +03:00
}
func ExampleAnalysis() {
c := &CustomerCol{}
c.Add(NewEnterpriseCustomer("A company"))
c.Add(NewIndividualCustomer("bob"))
c.Add(NewEnterpriseCustomer("B company"))
c.Accept(&AnalysisVisitor{})
// Output:
// analysis enterprise customer A company
// analysis enterprise customer B company
}