namespace simplefactory
{
using System;
public abstract class Vehicle
{
protected string m_typename ;
public string TypeName
{
get
{
return m_typename;
}
set
{
m_typename=value;
}
}
public abstract string Go();
}
public class Car:Vehicle
{
public Car()
{
m_typename="汽车";
}
public override string Go()
{
return "汽车在公路上开";
}
}
public class Train:Vehicle
{
public Train()
{
m_typename="火车";
}
public override string Go()
{
return "火车在铁轨上开";
}
}
public class Boat:Vehicle
{
public Boat()
{
m_typename="船";
}
public override string Go()
{
return "船在水里行";
}
}
public class CreatVehicle
{
public static Vehicle CreateaVehicle(string typeid)
{
switch(typeid.ToLower())
{
case "car":
return new Car();
break;
case "train":
return new Train();
break;
case "boat":
return new Boat();
break;
}
}
}
}
{
using System;
public abstract class Vehicle
{
protected string m_typename ;
public string TypeName
{
get
{
return m_typename;
}
set
{
m_typename=value;
}
}
public abstract string Go();
}
public class Car:Vehicle
{
public Car()
{
m_typename="汽车";
}
public override string Go()
{
return "汽车在公路上开";
}
}
public class Train:Vehicle
{
public Train()
{
m_typename="火车";
}
public override string Go()
{
return "火车在铁轨上开";
}
}
public class Boat:Vehicle
{
public Boat()
{
m_typename="船";
}
public override string Go()
{
return "船在水里行";
}
}
public class CreatVehicle
{
public static Vehicle CreateaVehicle(string typeid)
{
switch(typeid.ToLower())
{
case "car":
return new Car();
break;
case "train":
return new Train();
break;
case "boat":
return new Boat();
break;
}
}
}
}