implemented mediator pattern
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Abstractions ...
|
||||
type Visitor interface {
|
||||
VisitProductWithHighTask(ProductWithHighTax) float32
|
||||
VisitProductWithLowTask(ProductWithLowTax) float32
|
||||
@@ -13,18 +14,18 @@ type Visitable interface {
|
||||
Accept(Visitor) float32
|
||||
}
|
||||
|
||||
// Visitor
|
||||
type TaxVisitor struct {}
|
||||
func (v TaxVisitor) VisitProductWithHighTask(p ProductWithHighTax) float32 {
|
||||
fmt.Println("Visiting Product With High Tax ...")
|
||||
return p.Price * 1.3
|
||||
}
|
||||
|
||||
func (v TaxVisitor) VisitProductWithLowTask(p ProductWithLowTax) float32 {
|
||||
fmt.Println("Visiting Product With Low Tax ...")
|
||||
return p.Price * 1.1
|
||||
}
|
||||
|
||||
|
||||
// Visitable objects...
|
||||
type ProductWithHighTax struct {
|
||||
Price float32
|
||||
}
|
||||
|
Reference in New Issue
Block a user