class Light
{
public virtual void Display()
{
Console.WriteLine("I am light");
}
}
class Window
{
public virtual void Display()
{
Console.WriteLine("I am windows");
}
}
abstract class CarFactory
{
public abstract Light CreateLight();
public abstract Window CreateWindow();
}
class SmallLIght : Light
{
public override void Display()
{
Console.WriteLine("I am smalllight");
}
}
class SmallWindow : Window
{
public override void Display()
{
Console.WriteLine("I am smallwindow");
}
}
class SmallCarFactory : CarFactory
{
public override Light CreateLight()
{
return new SmallLIght();
}
public override Window CreateWindow()
{
return new SmallWindow();
}
}
class BigLIght : Light
{
public override void Display()
{
Console.WriteLine("I am biglight");
}
}
class BigWindow : Window
{
public override void Display()
{
Console.WriteLine("I am bigwindow");
}
}
class BigCarFactory : CarFactory
{
public override Light CreateLight()
{
return new BigLIght();
}
public override Window CreateWindow()
{
return new BigWindow();
}
}
static void Main(string[] args)
{
bool isSmall;
isSmall = true;
CarFactory factory = isSmall? (CarFactory )new SmallCarFactory(): (CarFactory)new BigCarFactory();
Light l = factory.CreateLight();
l.Display();
Window w = factory.CreateWindow();
w.Display();
}