using System;
using System.Collections.Generic;
using System.Text;
namespace CA
{
class Speaker
{
virtual public string SayHi()
{
return "hello";
}
}
class ChineseSpeaker : Speaker
{
public override string SayHi()
{
return "你好";
}
}
class WxSperker : Speaker
{
public override string SayHi()
{
return "@$!#";
}
}
class Screen
{
virtual public string Display()
{
return "This is Screen";
}
}
class ChineseScreen : Screen
{
public override string Display()
{
return "这是屏幕";
}
}
class WxScreen : Screen
{
public override string Display()
{
return "#@!@#$";
}
}
class XToyFactory
{
public virtual Screen CreateScreen()
{
return new Screen();
}
public virtual Speaker CreateSpeaker()
{
return new Speaker();
}
}
class XToyFactoryC:XToyFactory
{
public override Screen CreateScreen()
{
return new ChineseScreen();
}
public override Speaker CreateSpeaker()
{
return new ChineseSpeaker();
}
}
class XToy
{
private Screen screen;
private Speaker speaker;
public XToy(XToyFactory factory)
{
this.screen =factory.CreateScreen();
this.speaker =factory.CreateSpeaker();
}
public void Play()
{
speaker.SayHi();
screen.Display();
}
}
public class prop
{
public static void Main()
{
XToy xtoy = new XToy(new XToyFactory());
xtoy.Play();
XToy xtoy2 = new XToy(new XToyFactoryC());
xtoy2.Play();
Console.ReadKey();
}
}
}