This repository has been archived on 2021-09-07. You can view files and clone it, but cannot push or open issues or pull requests.
2020-09-07 10:30:22 -04:00

38 lines
559 B
Go

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