public abstract class VideoWiring
{
public abstract string PlayVideo();
}
public class Create
{
public static VideoWiring factory(string VideoName)
{
switch (VideoName)
{
case "DVD":
return new DVD();
case "VCD":
return new VCD();
}
return null;
}
}
public class VCD:VideoWiring
{
public override string PlayVideo()
{
return "正在播放播放VCD";
}
}
public class DVD : VideoWiring
{
public override string PlayVideo()
{
return "正在播放播放DVD";
}
}
看下这个例子
VideoWiring vw = Create.factory("DVD");
textBox1.Text= vw.PlayVideo();
vw = Create.factory("VCD");
textBox1.Text+=vw.PlayVideo();