forked from go/golangs_learn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
447 B
41 lines
447 B
3 years ago
|
|
||
|
```go
|
||
|
package visitor
|
||
|
|
||
|
import "fmt"
|
||
|
|
||
|
type IVisitor interface {
|
||
|
Visit()
|
||
|
}
|
||
|
|
||
|
type WeiBoVisitor struct {
|
||
|
|
||
|
}
|
||
|
|
||
|
func (w *WeiBoVisitor)Visit() {
|
||
|
fmt.Println("调用::WeiBoVisitor")
|
||
|
}
|
||
|
|
||
|
type WeiXinVisitor struct {
|
||
|
|
||
|
}
|
||
|
|
||
|
func (w *WeiXinVisitor)Visit() {
|
||
|
fmt.Println("调用::WeiXinVisitor")
|
||
|
}
|
||
|
|
||
|
type IElement interface {
|
||
|
Accept(v IVisitor)
|
||
|
}
|
||
|
|
||
|
type Element struct {
|
||
|
|
||
|
}
|
||
|
|
||
|
func (e *Element)Accept(v IVisitor) {
|
||
|
v.Visit()
|
||
|
}
|
||
|
```
|
||
|
* 访问者模式
|
||
|
|
||
|
*
|