Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created September 30, 2021 20:33
Show Gist options
  • Save dcomartin/b0ba9b835b4d2e1df5c7b5d2fa0a974d to your computer and use it in GitHub Desktop.
Save dcomartin/b0ba9b835b4d2e1df5c7b5d2fa0a974d to your computer and use it in GitHub Desktop.
public class PickupStop : Stop
{
public PickupStop(int stopId, Address address, DateTime scheduled)
: base(stopId, address, scheduled)
{
StopId = stopId;
Address = address;
}
}
public class DeliveryStop : Stop
{
public DeliveryStop(int stopId, Address address, DateTime scheduled)
: base(stopId, address, scheduled)
{
StopId = stopId;
Address = address;
}
}
public abstract class Stop
{
public int StopId { get; protected set; }
public StopStatus Status { get; private set; } = StopStatus.InTransit;
public Address Address { get; protected set;}
public DateTime Scheduled { get; }
public DateTime? Departed { get; protected set; }
public Stop(int stopId, Address address, DateTime scheduled)
{
StopId = stopId;
Address = address;
Scheduled = scheduled;
}
public void Arrive()
{
if (Status != StopStatus.InTransit)
{
throw new InvalidOperationException("Stop has already arrived.");
}
Status = StopStatus.Arrived;
}
public void Depart()
{
if (Status == StopStatus.Departed)
{
throw new InvalidOperationException("Stop has already departed.");
}
if (Status == StopStatus.InTransit)
{
throw new InvalidOperationException("Stop hasn't arrived yet.");
}
Status = StopStatus.Departed;
Departed = DateTime.UtcNow;
}
}
public enum StopStatus
{
InTransit,
Arrived,
Departed
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment