代理模式
代理模式
代理接口
package proxy
type proxy interface{
sell()
}
火车站售票
package proxy
type Station struct{
name string
}
func NewStation(name string) *Station{
return &Station{name:name}
}
func (s *Station)sell(){
fmt.Println("身份证,目的地")
}
车票代售点
package proxy
type Shop struct{
station *Station
}
func NewShop(station *Station) *Shop{
return &Shop{station:station}
}
func (s *Shop)sell(){
s.station.sell()
fmt.Println("留下10元手续费!")
}
测试文件
package proxy
func TestProxy(t *testing.T){
shop := NewShop(NewStation("北京南站"))
shop.sell()
}

浙公网安备 33010602011771号