Created
October 30, 2013 04:19
-
-
Save balopat/7227154 to your computer and use it in GitHub Desktop.
This file contains 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
package com.balopat.timeinjection | |
import java.util.Date | |
class RealClock extends Clock { | |
def getTime() = new Date() | |
} | |
trait Clock { | |
def getTime(): Date | |
} |
This file contains 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
package com.balopat.timeinjection | |
import java.util.Date | |
class Wall(clock: Clock) { //injection!!! | |
var messages = List[Message]() | |
def message(message: String) { | |
messages ::= Message(message, clock.getTime()) //we are using clock as a service to get time | |
} | |
} | |
case class Message(message: String, createdAt: Date) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment