mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-29 08:26:04 +03:00
26 lines
419 B
Go
26 lines
419 B
Go
package strategy
|
|
|
|
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)
|
|
}
|
|
|
|
type Multiplication struct{}
|
|
|
|
func (Multiplication) Apply(lval, rval int) int {
|
|
return lval * rval
|
|
}
|
|
|
|
type Addition struct{}
|
|
|
|
func (Addition) Apply(lval, rval int) int {
|
|
return lval + rval
|
|
}
|