POO Avancée & Architecture Logicielle avec C#
Primary constructors et invariants
public class Money(decimal amount, string currency)
{
public decimal Amount { get; } = amount >= 0 ? amount : throw new ArgumentOutOfRangeException(nameof(amount));
public string Currency { get; } = !string.IsNullOrWhiteSpace(currency) ? currency : throw new ArgumentException("Currency required");
}
- La validation arrive tôt.
- Les propriétés publiques restent stables.