Skip to content

Instantly share code, notes, and snippets.

@balopat
Created October 30, 2013 04:19
Show Gist options
  • Save balopat/7227154 to your computer and use it in GitHub Desktop.
Save balopat/7227154 to your computer and use it in GitHub Desktop.
package com.balopat.timeinjection
import java.util.Date
class RealClock extends Clock {
def getTime() = new Date()
}
trait Clock {
def getTime(): Date
}
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