I have an interface and a class that implements that interface.
I have a requirement that the class has a dependency on ITimer. A private member is created and a constructor argument is passed in and the private member is assigned to that constructor parameter.
How do I make it so that the interface has this ITimer declared somehow but not as a property? Its not as if I can’t test MyClass properly but I thought the interface was supposed to be a contract that the class must adhere to therefore my class has a dependency so how do I make this appear in the interface?
public interface IMyInterface
{
void DoSomething();
}
public class MyClass : IMyInterface
{
private ITimer MyTimer;
public MyClass(ITimer timer)
{
MyTimer = timer;
}
public void DoSomething()
{
}
}
This cannot be done with an interface in C#. What you could do is to inherit from an abstract class instread of an interface.