Last active
August 29, 2015 14:03
-
-
Save edeustace/3348ae044e5054b2cd3b 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
| //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