I want to understand interface implementation because I have been having errors that doesn't make sense to me. I have this interface and 2 abstract classes:
public interface ICashBuddieHelper
{
IHelper FilterOnContext(DbBuddieContext db);
IHelper PrepareResultModel(InputModelBase message);
IHelper SortSet();
ResultModelBase ToResultModel(InputModelBase message);
}
public abstract class ResultModelBase
{
...
}
public abstract class InputModelBase
{
...
}
and I have two classes that implement this Helper interface but with more derived versions of the input parameters and return types which are abstract classes as shown above. I have implemented the IHelper interface with the following classes
public class BankAccountHelper : ICashBuddieHelper
{
public ICashBuddieHelper FilterOnContext(DbBuddieContext db){...}
public ICashBuddieHelper PrepareResultModel(BankAccountInputModel message){...}//error
public ICashBuddieHelper SortSet(){...}
public ResultModelBase ToResultModel(BankAccountInputModel message){...}//error
}
public class CashFlowHelper : ICashBuddieHelper
{
public ICashBuddieHelper FilterOnContext(DbBuddieContext db){...}
public ICashBuddieHelper PrepareResultModel(CashFlowInputModel message){...}//error
public ICashBuddieHelper SortSet(){...}
public ResultModelBase ToResultModel(CashFlowInputModel message){...}//error
}
From the code snippet above, you can see that two lines in the implementing classes give the error that says:
'CashFlowHelper' does not implement interface member 'ICashBuddieHelper.PrepareResultModel(InputModelBase)' 'CashFlowHelper' does not implement interface member 'ICashBuddieHelper.ToResultModel(InputModelBase)'
Please can someone tell me what I am doing wrong? I would like to understand my misunderstanding of interfaces. Surely I can use a more derived type in the place of an abstract class. I don't understand what the compiler is complaining about.
publicin CashFlowHelper (in front of the interface method signatures). The interface requires that they're public.void IMyInterface.DoSomething { }.Ctrl+.and just hitEnter, and because I've gone too fast, I accidentally end up with a new class in the local namespace with the same name as a class in another namespace. Is there a chance you have done this? Or a chance that the implementation and interface refer to two distinct classes with the same name?