Skip to content

Instantly share code, notes, and snippets.

@dnasca
Created March 17, 2015 06:37
Show Gist options
  • Select an option

  • Save dnasca/e74d276c670eee9bdf85 to your computer and use it in GitHub Desktop.

Select an option

Save dnasca/e74d276c670eee9bdf85 to your computer and use it in GitHub Desktop.
using System;
interface IA
{
void AMethod(); //declare method
//method implemented in class A
}
public class A : IA //inherit from interface A
{
public void AMethod()
{
Console.WriteLine("AMethod called");
}
}
interface IB
{
void BMethod(); //declare method
//method implemented in class B
}
public class B : IB //inherit from interface B
{
public void BMethod()
{
Console.WriteLine("BMethod called");
}
}
public class AB : IA, IB //inherit from interface A and B
{
private A a = new A(); //instantiate object A with reference of 'a'
private B b = new B(); //instantiate object B with reference of 'b'
public void AMethod()
{
a.AMethod(); //invoke method from class A
}
public void BMethod()
{
b.BMethod(); //invoke method from class B
}
}
public class Program
{
public static void Main()
{
AB ab = new AB(); //instantiate object AB with reference of 'ab'
//now it is possible to access both methods, from seperate classes because each class inherits from multiple interfaces
ab.AMethod();
ab.BMethod();
Console.ReadKey();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment