Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created October 29, 2025 15:13
Show Gist options
  • Save dcomartin/276d9af0ef6e72094b772bfb62f4280f to your computer and use it in GitHub Desktop.
Save dcomartin/276d9af0ef6e72094b772bfb62f4280f to your computer and use it in GitHub Desktop.
public interface IDeliveryTimingPolicy
{
bool IsLate(Shipment shipment);
}
public class StandardDeliveryTiming : IDeliveryTimingPolicy
{
private readonly DateTime _now;
public StandardDeliveryTiming(DateTime now)
{
_now = now;
}
public bool IsLate(Shipment shipment)
{
return _now > shipment.DeliveryDate;
}
}
public class BufferDeliveryTiming : IDeliveryTimingPolicy
{
private readonly DateTime _now;
private readonly TimeSpan _buffer;
public BufferDeliveryTiming(DateTime now, TimeSpan buffer)
{
_now = now;
_buffer = buffer;
}
public bool IsLate(Shipment shipment)
{
return _now > shipment.DeliveryDate.Add(_buffer);
}
}
public class Shipment
{
public required DateTime DeliveryDate { get; init; }
public bool IsLate(IDeliveryTimingPolicy policy)
{
return policy.IsLate(this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment