Skip to content

Instantly share code, notes, and snippets.

@dahlbyk
Created August 31, 2013 17:59
Show Gist options
  • Save dahlbyk/6399709 to your computer and use it in GitHub Desktop.
Save dahlbyk/6399709 to your computer and use it in GitHub Desktop.
Clarifying the D in SOLID...

Dependency Inversion Principle says do this:

class Foo
{
    IBar bar;

    public Foo(IBar bar) {
        this.bar = bar;
    }

    void Baz() {
        // Use bar
    }
}

Or this:

class Foo
{
    void Baz(IBar bar) {
        // Use bar
    }
}

Instead of this:

class Foo
{
    IBar bar = new Bar();

    void Baz() {
        // Use bar
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment