Skip to content

Instantly share code, notes, and snippets.

@coderunner
Created August 12, 2011 02:21
Show Gist options
  • Select an option

  • Save coderunner/1141302 to your computer and use it in GitHub Desktop.

Select an option

Save coderunner/1141302 to your computer and use it in GitHub Desktop.

Revisions

  1. coderunner revised this gist Feb 23, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,12 @@
    public class ExampleClass
    {
    private DependencyInterface dependency;
    private final DependencyInterface dependency;

    //no dependency injection
    public ExampleClass()
    {
    //this makes the class hard to test
    dependency = new Dependency();
    this.dependency = new Dependency();
    //...
    }

  2. coderunner revised this gist Aug 12, 2011. 1 changed file with 26 additions and 26 deletions.
    52 changes: 26 additions & 26 deletions gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -1,31 +1,31 @@
    public class ExampleClass
    {
    private DependencyInterface dependency;
    private DependencyInterface dependency;

    //no dependency injection
    public ExampleClass()
    {
    //this makes the class hard to test
    dependency = new Dependency();
    //...
    }

    //no dependency injection
    public ExampleClass()
    {
    //this makes the class hard to test
    dependency = new Dependency();
    //...
    }
    //inject the concrete dependency
    public ExampleClass(Dependency dependency)
    {
    //this makes the class slightly more testable
    //if proper test tools are used because
    //the dependency can be setup or mocked
    this.dependency = dependency;
    //...
    }

    //inject the concrete dependency
    public ExampleClass(Dependency dependency)
    {
    //this makes the class slightly more testable
    //if proper test tools are used because
    //the dependency can be setup or mocked
    this.dependency = dependency;
    //...
    }

    //inject the interface
    public ExampleClass(DependencyInterface dependency)
    {
    //this makes the class easily testable as a test
    //implementation can be supplied
    this.dependency = dependency;
    //...
    }
    //inject the interface
    public ExampleClass(DependencyInterface dependency)
    {
    //this makes the class easily testable as a test
    //implementation can be supplied
    this.dependency = dependency;
    //...
    }
    }
  3. coderunner created this gist Aug 12, 2011.
    31 changes: 31 additions & 0 deletions gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    public class ExampleClass
    {
    private DependencyInterface dependency;

    //no dependency injection
    public ExampleClass()
    {
    //this makes the class hard to test
    dependency = new Dependency();
    //...
    }

    //inject the concrete dependency
    public ExampleClass(Dependency dependency)
    {
    //this makes the class slightly more testable
    //if proper test tools are used because
    //the dependency can be setup or mocked
    this.dependency = dependency;
    //...
    }

    //inject the interface
    public ExampleClass(DependencyInterface dependency)
    {
    //this makes the class easily testable as a test
    //implementation can be supplied
    this.dependency = dependency;
    //...
    }
    }