Skip to content

Instantly share code, notes, and snippets.

@v6ak
Created July 17, 2013 16:36
Show Gist options
  • Select an option

  • Save v6ak/6022250 to your computer and use it in GitHub Desktop.

Select an option

Save v6ak/6022250 to your computer and use it in GitHub Desktop.
trait ICalculatingStrategy {
def calculate(a: Int, b: Int): Int
}
object CalculatingStrategies {
@inline val Add = 2
@inline val Multiply = 3
}
val CalculatingOperations = Map(
CalculatingStrategies.Add -> new ICalculatingStrategy{
override def calculate(a: Int, b: Int) = a + b
},
CalculatingStrategies.Multiply -> new ICalculatingStrategy{
override def calculate(a: Int, b: Int) = a * b
}
)
CalculatingOperations(CalculatingStrategies.Multiply).calculate(3, 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment