I overheard the below and was asked to confirm this statement:
"SOLID/TDD encourages one implementation for one interface, this is not real world and goes against the point of interfaces doesn't it?"
I initially agreed as all online examples of TDD and DI all follow typical IRepository/MyRepository examples where there is only one implementation. After further thought I didn't agree.
What I'm trying to do is provide proof that it doesn't and also an example of where there can be multiple implementations of one interface and show how it works in terms of DI.
I was hoping people could help me with this.
UPDATE: Whilst I understand the concepts of DI and Unit Testing what I'm trying to show is how we can have multiple classes in production implementing one interface.
UPDATE2: Having thought of a simple example, here is a possible implementation of multiple implementations however it still doesn't really answer what I want. What if you had a constructor that had a single dependency on ILogger or IDataProvider or ISomething:
public interface ILogger
{
void Write(string data);
}
public class FileLogger : ILogger
{
void Write(string data)
{
//
}
}
public class DBLogger : ILogger
{
void Write(string data)
{
//
}
}
public class EventViewerLogger : ILogger
{
void Write(string data)
{
//
}
}
public class Calculator
{
private IEnumberable<ILogger> loggers;
public Calculator(IEnumberable<ILogger> loggers)
{
this.loggers = loggers;
}
public int Add(int a, int b)
{
var result = a + b;
foreach(var logger in loggers)
{
logger.Write("Result was " + logger);
}
}
}