1
0
mirror of https://github.com/tmrts/go-patterns.git synced 2024-11-25 22:46:05 +03:00

behavioral/visitor: add more explanations to visitor implementation

This commit is contained in:
Serge Bishyr 2017-10-18 16:38:00 +03:00
parent 7ba8e00dff
commit 6df1cb57f1

View File

@ -4,6 +4,7 @@ Visitor behavioral design pattern provides a way to separate an algorithm from a
It gives the ability to extend the existing object without modifying the object itself. It gives the ability to extend the existing object without modifying the object itself.
## Implementation ## Implementation
Implementation of a visitor that can add functionality to the shape structures.
```go ```go
type Visitor interface { type Visitor interface {
@ -34,7 +35,7 @@ func (l Line) accept(v Visitor) string {
## Usage ## Usage
### JSON marshaller ### JSON marshaller
Using visitor to marshal shapes to JSON
```go ```go
type JsonVisitor struct { type JsonVisitor struct {
} }
@ -57,7 +58,7 @@ fmt.Println(line.accept(&jsonVisitor))
``` ```
### XML marshaller ### XML marshaller
Using visitor to marshal shapes to XML
```go ```go
type XmlVisitor struct { type XmlVisitor struct {
} }