using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Traffic
{
public enum DrivingMode
{
燃油发动机,
人力,
电动
}
public enum Function
{
载货,
载人
}
public abstract class TrafficTool
{
#region Fields
protected string _name;
public string Name
{
get { return _name; }
}
protected double _speed;
public double Speed
{
get { return _speed; }
}
protected DrivingMode _drivenMode;
public DrivingMode DrivenMode
{
get { return _drivenMode; }
}
protected Function _function;
public Function Function
{
get { return _function; }
}
#endregion
#region Constructors
public TrafficTool(string name, double speed, DrivingMode mode, Function function)
{
this._name = name;
this._speed = speed;
this._drivenMode = mode;
this._function = function;
}
#endregion
}
public class Car : TrafficTool
{
private double _initialSpeed;
public double InitialSpeed
{
get { return _initialSpeed; }
}
public Car(string name, double speed)
: base(name, speed, DrivingMode.燃油发动机, Function.载人)
{
this._initialSpeed = 40;
}
}
public class Bicycle : TrafficTool
{
public Bicycle(string name)
: base(name, 10, DrivingMode.人力, Function.载人)
{
}
//似乎有点牵强
protected Bicycle(string name, double speed, DrivingMode mode)
: base(name, speed, mode, Function.载人)
{
}
}
public class ElectricPowerBicycle : Bicycle
{
public ElectricPowerBicycle(string name)
: base(name, 30, DrivingMode.电动)
{
}
}
public class Truck : TrafficTool
{
public Truck(string name)
: base(name, 45, DrivingMode.燃油发动机, Function.载货)
{
}
}
}

贾大牙 最后编辑于 2010-02-25 00:25:28