Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created April 28, 2021 21:20
Embed
What would you like to do?
public abstract class Stop
{
public int StopId { get; set; }
public StopStatus Status { get; set; }
public int Sequence { get; set; }
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment