Modify strategy pattern

This commit is contained in:
Tamer Tas committed 2016-02-20 17:32:02 +02:00
1 parent b10a4f9cac
commit b1ddd2651b
2 files changed
+19 -15

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
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
}