Created
July 17, 2013 16:36
-
-
Save v6ak/6022250 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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