Skip to content

Instantly share code, notes, and snippets.

@edeustace
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save edeustace/3348ae044e5054b2cd3b to your computer and use it in GitHub Desktop.

Select an option

Save edeustace/3348ae044e5054b2cd3b to your computer and use it in GitHub Desktop.
//A trait with a function 'do'
trait Thingy {
def do : String
}
//A global object that implements Thingy
object Thingy extends Thingy{
def do = "thing"
}
//Approach 1: Wiring a global object
//Pros: less code
//Cons: hardwired dependency - makes it harder to isolate and test
class ClientOne {
def do = Thingy.do
}
//Approach 2: Don't wire in the trait instead declare the depenency
//Pros: allows isolation testability
//Cons: requires more code for final wiring
trait CientTwo {
def thingy : Thingy
def do = thingy.do
}
//Approach 2 cont.. then when wiring up the app assign the dependency
new ClientTwo{
def thingy = Thingy
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment