implemented mediator pattern

This commit is contained in:
ismayilmalik
2018-01-16 00:53:06 +03:00
parent 43ba305859
commit 1ea149edd8
3 changed files with 77 additions and 2 deletions

View File

@@ -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
}