[C#] interface Sample
interface ISampleInterface
{
void SampleMethod();
}
class CSampleClass1 : ISampleInterface
{
void SampleMethod()
{
// Method implementation.
}
}
class CSampleClass2 : ISampleInterface
{
void SampleMethod()
{
// Method implementation.
}
}
class Program
{
static void Main()
{
ISampleInterface a = CreateInstance(1);
ISampleInterface b = CreateInstance(2);
a.SampleMethod();
b.SampleMethod();
}
static public ISampleInterface CreateInstance(int n)
{
switch (n)
{
case 1:
return new CSampleClass1();
case 2:
return new CSampleClass2();
default:
return new CSampleClass1();
}
}
}