type IObject interface {
ObjDo(action string)
}
type Object struct {
action string
}
func (obj *Object) ObjDo(action string) {
fmt.Printf("I can, %s", action)
}
type PatternObject struct {
object *Object
}
func (p *PatternObject) ObjDo(action string) {
if p.object == nil {
p.object = new(Object)
}
if action == "Run" {
p.object.ObjDo(action)
}
}
|
2 |
1 |
type Operator interface {
Apply(int, int) int
}
type Operation struct {
Operator Operator
}
func (o *Operation) Operate(leftValue, rightValue int) int {
return o.Operator.Apply(leftValue, rightValue)
}
|
1 |
2 |
type Operator interface {
Apply(int, int) int
}
type Operation struct {
Operator Operator
}
func (o *Operation) Operate(leftValue, rightValue int) int {
return o.Operator.Apply(leftValue, rightValue)
}
|
1 |
2 |