Make two interfaces IA and IB :
public interface IA { public void methodA(int value); } public interface IB { public void methodB(int value); }
Next, make A implement IA and B implement IB .
public class A : IA { public int fooA { get; set; } public void methodA(int value) { fooA = value; } } public class B : IB { public int fooB { get; set; } public void methodB(int value) { fooB = value; } }
Then implement your class C as follows:
public class C : IA, IB { private A _a; private B _b; public C(A _a, B _b) { this._a = _a; this._b = _b; } public void methodA(int value) { _a.methodA(value); } public void methodB(int value) { _b.methodB(value); } }
This is usually a bad design because you can use the A and B method with the same name and variable types as foo(int bar) , and you will need to decide how to implement it, or if you just call foo(bar) on both _a and _b . As suggested elsewhere, you should consider the .A and .B properties instead of combining the two classes.
Seph
source share