In my Repository class:
public class DeliveryRepository : IDeliveryRepository
{
private readonly List<Delivery> deliveries = new List<Delivery>();
public Delivery Add(Delivery item)
{
if (item == null)
{
throw new ArgumentNullException("item");
}
deliveries.Add(item);
return item;
}
}
...I could implement my Add()
method this way:
public Delivery Add(Delivery item)
{
Contract.Requires(item != null);
deliveries.Add(item);
return item;
}
...or this way instead:
public Delivery Add(Delivery item)
{
Contract.Requires<ArgumentNullException>(item != null, "item");
deliveries.Add(item);
return item;
}
Which of the three is best? Does it matter? Just a matter of style/preference?
Are they 2 of one, a pair of the other, and a couple of the third?