private void Form1_Load(object sender, EventArgs e)
{
//调用
car p = dric.get("ben");
string nam = p.drice();
MessageBox.Show(nam);
}
/// <summary>
/// 抽象
/// </summary>
public abstract class car
{
private String name;
public abstract string drice();
public string getname()
{
return name;
}
}
/// <summary>
///车
/// </summary>
public class ben : car
{
public override string drice()
{
return "开始" + getname() + "-------go--";
}
}
/// <summary>
/// 工厂
/// </summary>
public class dric
{
public static car get(string name)
{
car c = null;
if ("ben".Equals(name))
c = new ben();
return c;
}
}
转载于:https://www.cnblogs.com/net520/p/7953472.html