C#: How to override functions in one class without multiple inheritance from different services -


i have service servicea inherited soaphttpclientprotocol.

also, have class processinghelperclass, inherited servicea overriden functions , couple of additional fields.

i have lots of servicea kind of services. , need create class overriden functions of them.

my question: there way create 1 class overriding functions , additional fields different services don't have create new class every service include.

and if question bad in sense of programming, glad learn why, i'm newbie

upd: pseudo code reference.cs (file service proxy class)

public partial class servicea : soaphttpclientprotocol {      public void method1(){};      public void method2(){};      //etc...  } 

processinghelperclass.cs

 public class processinghelperclass: servicea, idisposable  {      private xmlwriter _xmlwriter;      public string stringa => xmlwriter == null? "" : _xmlwriter.xml;      ...      protected override xmlwriter getwriterformessage(system.web.services.protocols.soapclientmessage message, int buffersize)      {         var writer = base.getwriterformessage(message, buffersize);         _xmlwriterspy = new xmlwriterspy(writer);         return _xmlwriterspy;      }  } 

program.cs

static void main(string[] args) {    processinghelperclass client = new processinghelperclass();    client.method1();    console.writeline(client.stringa); } 

in c#, can inherit 1 class. makes overriding methods multiple classes in 1 class not valid strategy. can however, inherit multiple interfaces. if can inherit multiple interfaces, can implement these interfaces in 1 class.

public interface iservicea {    bool isvisible(); } public interface iserviceb {    void setvalue(); } public class someclass : iservicea, iserviceb {    public bool isvisible(){}    public void setvalue(){} } 

the downside is, cannot re-use implemented method because there no implemented methods. can countered implementing classes each interface seperately, , combining objects of these classes in 1 'superclass';

public interface iservicea {    bool isvisible(); } public interface iserviceb {    void setvalue(); } public class servicea : iservicea {    public bool isvisible(){} } public class serviceb : iserviceb {    public void setvalue(){} } public class someclass : iservicea, iserviceb {    private iservicea _a;    private iserviceb _b;     public someclass(iservicea a, iserviceb b)    {       _a = a;       _b = b;    }     public bool isvisible()    {      _a.isvisible(); // if want re-use    }    public void setvalue()    {       // implement logic here if want 'override'    } } 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo