Home:ALL Converter>Why can't implement the interface this way

Why can't implement the interface this way

Ask Time:2018-06-08T21:59:04         Author:jeffkenn

Json Formatter

I need to add a variable to the signature of the SendAsync method but when I try to do that I get an error that I need implement interface that matches the SendAsync without the new variable.

Can I have both? I guess I'm trying to overload an interface.

Code below.

public class EmailService : IIdentityMessageService 
{
    public async Task SendAsync(IdentityMessage message, string OAEmailAddress)
    {
        await configSendGridasync(message, OAEmailAddress);
    }
}

Author:jeffkenn,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/50762321/why-cant-implement-the-interface-this-way
MakePeaceGreatAgain :

The interface is a contract you have to fullfill exactly. In particular how should a client know when to use two and when to use only a single parameter? Imagine you´d have an interface IMyInterface whose only method DoSomething doesn´t have any parameters:\n\nIMyInterface instance = getInstance();\ninstance.DoSomething();\n\n\nNo you have a class implementing that interface:\n\nclass MyClass : IMyInterface\n{\n public void DoSomething(string arg1, string arg2) { ... }\n}\n\n\nHere all you know is that instance is of type IMyInterface whose DoSomething-method doesn´t expect anything. How should a user of your interface know that the actual type (in this case MyClass) however needs more parameters to call the method? In fact he does not even know that getInstance even returned an instance of type MyClass, it could have been also any other class that implements the interface. \n\nThat´s why interfaces exist: they clearly state what you can do with an instance and how to do it. Everything beyond this needs some extension to that interface, e.g. by using another method within that interface, or by extending the interface with a second interface.",
2018-06-08T14:03:39
Neil :

The interface is a specification that means any implementation MUST provide at least those functions specified. You are free to implement more functions that those specified.",
2018-06-08T14:03:53
yy