asp.net - C# Multiple Inheritance with Interfaces -


public interface ia {   void dosomething();   void calculate();  }  public interface ib {   void dosomethingelse();   void calculate(); }  public class : ia {   void dosomething() { }   void calculate() {} }  public class b : ib {   void dosomethingelse() { }   void calculate() {} }  public class c : ia, ib {      //how can implement calculate() in class b , dosomething() in class a? } 

how can avoid duplicate code in class c. reference: how simulate multiple inheritance in c#. don't want write full methods again in class c. help.

assuming ia.calculate() not same ib.calculate() , therefore can't make ib inherit ia, can implement both interfaces in c delegating execution on private instances of a , b:

public class c : ia, ib {     private _a;     private b _b;      public c()     {         this._a = new a();         this._b = new b();     }      public void dosomething()     {         this._a.dosomething();     }     void ia.calculate()     {         this._a.calculate();     }     public void dosomethingelse()     {         this._b.dosomethingelse();     }     void ib.calculate()     {         this._b.calculate();     } } 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -