implemented proxy pattern

This commit is contained in:
Ismayil_Niftaliyev 2018-01-17 16:31:15 +03:00
parent ad9b1057cb
commit 28814bb7a3

View File

@ -0,0 +1,37 @@
package proxy
import "errors"
type Human struct {
Gender string
Age int
}
type Bar interface {
Welcome(Human) error
}
type OpenBar struct {
Visitors []Human
}
func (b *OpenBar) Welcome(h Human) error {
b.Visitors = append(b.Visitors, h)
return nil
}
type BarProxy struct {
bar Bar
}
func (b *BarProxy) Welcome(h Human) error {
if h.Gender == "female" && h.Age < 20 {
return errors.New("Females under 20 not allowed.")
}
if h.Gender == "male" && h.Age < 18 {
return errors.New("Males under 18 not allowed.")
}
return b.bar.Welcome(h)
}