-
-
Save dcomartin/276d9af0ef6e72094b772bfb62f4280f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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