hi, i have read a article using "interface as callback".
https://www.c-sharpcorner.com/UploadFile/1c8574/delegate-used-for-callback-operation/
then I see that many occasion, Api provides the interface for consumer. I wonder if they are usually working like this way? I think there are 4 steps
here is my code (please correct my comment if i misunderstand, thanks!)
first there is a Api
class Api
{
public void StartNewTask(IFurtherProcess Interface_Obj_Feedback_from_user)
{
Console.WriteLine("started task");
Interface_Obj_Feedback_from_user.process();
}
}
interface IFurtherProcess
{
void process();
}
then there is Class to implement the interface by Consumer
public class ProcessClass1 : IFurtherProcess
{
public void process()
{
Console.WriteLine("add");
}
}
public class ProcessClass2 : IFurtherProcess
{
public void process()
{
Console.WriteLine("sub");
}
}
then there is a ApiConsumer Class:
class ApiConsumer
{
public IFurtherProcess _ifp=null;
public ApiConsumer(IFurtherProcess ifp)
{
this._ifp = ifp;
}
public void CallApiMethod()
{
Api cs = new Api();
cs.StartNewTask(_ifp);
}
}
finally, it is the main:
static void Main(string[] args)
{
ApiConsumer apiConsumer = new ApiConsumer(new ProcessClass2());
apiConsumer.CallApiMethod();
Console.ReadLine();
}
What I have tried:
furthermore, it seems to have too many layer. Is it so called "wrapper" what i am doing above? main->apiconsumer->api .