What? No, it works great to add numbers beside 3:
class Sample {
public Sample(IThreeProvider threeProvider) {
_threeProvider = threeProvider;
}
private readonly IThreeProvider _threeProvider;
public int AddThree(int val)
{
return val + _threeProvider.Get().AsInt();
}
}
public class MyCustomThreeProvider() {
public int Get() { return 4; }
}
Now you can just do: var sample = new Sample(new MyCustomThreeProvider());
sample.AddThree(2);
And get 6, as you'd expect. ..So long as you read and fully understood the entire codebase first, anyway.I think this actually highlights one of the bigger problems in adding unnecessary indirections: that it practically begs for strange work-around and hacks and strange layers added on top. It becomes too difficult to change the underlying classes -- eg, changing the AddThree method to handle an arbitrary number means also changing the entire concept of ThreeProviders and everywhere that calls or tests any of the related code -- and as a result it's faster to workaround.