dimanche 22 février 2015

C# Pattern for aggregating interface methods into one generic method

I'm searching for a pattern to aggregating interface methods into one generic method.


Better to make an example of what I'm trying to do


Consider that I have an interface with 20 methods



interface MultiMethod{
public TypeA A (p1,p2);
public TypeA B (p1);
public TypeC C (p5,p3,p2);
.
.
.
}


Implementation Class



class MultiMethodeService : MultiMethod


In the MultiMethodeService I need to Implement all Interface methods, but the implementation of the methods is not real different.


Like:



public TypeA A (p1,p2){
proxy.call("remoteA").params(p1,p2);
}
public TypeB B (p1){
proxy.call("remoteB").params(p1);
}


I want to replace the implementation of the methods with one generic method that uses reflection.


The generic method derives



  • the parameters form the MultiMethod interface the method name from

  • the MultiMethode interface to invoke a proxy call


But how is it possible, when I have a generic method to also have the equal semantic like without a generic implementation. When I afterwords want to use the service object of MultiMethodService like :



var service = new MultiMethodService()
service.A(p1,p2)


Some naive idea was to implement an enum{"A","B"}



service.callGeneric(enum.A, p1,p2);
service.callGeneric(enum.B, p1);


which is not really nice.


If you could provide any pattern or idea, your help is highly appreciated.


Aucun commentaire:

Enregistrer un commentaire