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
}
}