私はポリモーフィズムが初めてで、少し苦労しています。
私は3つのクラスを持っています。基本クラスである Visit クラス。次に、配送と集荷です。
配達も集荷も訪問です。
訪問クラスを参照して、配達と集荷の両方に対応できるようにしたいです。
public virtual class Visit
{
private string customerName;
private string customerAddress;
private DateTime arrivalTime;
public string customername
{
//name properties
set { customerName = value; }
get { return customerName; }
}
public string customeraddress
{
//address properties
set { customerAddress = value; }
get { return customerAddress; }
}
public DateTime arrivaltime
{
//time proerties
set { arrivalTime = value; }
get { return arrivalTime; }
}
}
public class Delivery : Visit
/*
* Polymorphism, Delivery is also a visit.
*/
{
private string deliveryAddress;
private string deliveryName;
public string deliveryaddress
{
set { deliveryAddress = value; }
get { return deliveryAddress; }
}
public string deliveryname
{
set { deliveryName = value; }
get { return deliveryName; }
}
public string ToString()
{ //return Delivery details
return deliveryname + " " + deliveryaddress + " " + customername + " " + customeraddress + " " + arrivaltime;
}
}
public class Pickup : Visit
/*
* Polymorphism, pickup is also a visit.
*/
{
public string ToString()
{ //return Pickup details
return customername + " " + customeraddress + " " + arrivaltime.ToString();
}
}
}