public SoldArticle(IWarranty moneyBackGuarantee, IWarranty expressWarranty, IWarrantyMapFactory rulesFactory) { MoneyBackGuarantee = moneyBackGuarantee ?? throw new ArgumentNullException(nameof(moneyBackGuarantee)); NotOperationalWarranty = expressWarranty ?? throw new ArgumentNullException(nameof(expressWarranty)); CircuitryWarranty = VoidWarranty.Instance; OperationalStatus = DeviceStatus.AllFine(); WarrantyMap = rulesFactory.Create(ClaimMoneyBack, ClaimNotOperationalWarranty, ClaimCircuitryWarranty); }
//remember to start with a proof of concept - piece of code which works correctly. //then introduce new types to simplify code. //Func<T> delegaes dont have arugments names, only types which makes them indistguishable from one another. public FlexibleSoldArticle(IWarranty moneyBack, IWarranty express, IWarrantyMapFactory rulesFactory) { if (moneyBack == null) { throw new ArgumentNullException(nameof(moneyBack)); } if (express == null) { throw new ArgumentNullException(nameof(express)); } this.MoneyBackGuarantee = moneyBack; this.NotOperationalWarranty = express; this.CircuitryWarranty = VoidWarranty.GetInstance; //Externalized the rules that apply to warranty claiming processes. this.WarrantyMap = rulesFactory.Create(this.ClaimMoneyBack, this.ClaimNotOperationalWarranty, this.ClaimCircuitryWarranty); }
public SoldArticle(IWarranty moneyBack, IWarranty express, IWarrantyMapFactory rulesFactory) { if (moneyBack == null) { throw new ArgumentNullException(nameof(moneyBack)); } if (express == null) { throw new ArgumentNullException(nameof(express)); } this.MoneyBackGuarantee = moneyBack; this.ExpressWarranty = VoidWarranty.Value; this.NotOperationalWarranty = express; this.CircuitryWarranty = VoidWarranty.Value; // With objects methods calls this.OperationalStatus = DeviceStatus.AllFine(); this.WarrantyMap = rulesFactory.Create( this.ClaimMoneyBack, this.ClaimNotOperationalWarranty, this.ClaimCircuitryWarranty); }
public SoldArticle(IWarranty moneyBack, IWarranty express, IWarrantyMapFactory rulesFactory) { // Constructor preconditions if (moneyBack == null) { throw new ArgumentException(nameof(moneyBack)); } if (express == null) { throw new ArgumentException(nameof(express)); } this.MoneyBackWarrantee = moneyBack; this.NotOperationalWarranty = express; this.CircuitryWarranty = VoidWarranty.Instance; this.OperationalStatus = DeviceStatus.AllFine(); this.WarrantyMap = rulesFactory.Create( this.ClaimMoneyBack, this.ClaimNotOperationalWarranty, this.ClaimCircuitryWarranty); }