Example #1
0
        // warning: beware of bool method arguments
        // Their appearance is the indicator of leaving the OO design principles
        private static void ClaimWarrenty(SoldArticle article)  // bool flags
        {
            DateTime now = DateTime.Now;

            article.MoneyBackGuarantee.Claim(now, () => Console.WriteLine("Offer money back"));
            article.ExpressWarranty.Claim(now, () => Console.WriteLine("Offer repair"));

            //if (article.MoneyBackGuarantee.IsValidOn(now))
            //{
            //    Console.WriteLine("Offer money back");
            //}
            //if (article.ExpressWarranty.IsValidOn(now))
            //{
            //    Console.WriteLine("Offer repair");
            //}
        }
Example #2
0
        public void Main()
        {
            DateTime sellingDate   = new DateTime(2019, 12, 9);
            TimeSpan moneyBackSpan = TimeSpan.FromDays(30);
            TimeSpan warrantySpan  = TimeSpan.FromDays(365);

            IWarranty moneyBack = new TimeLimitedWarranty(sellingDate, moneyBackSpan);
            //IWarranty warranty = new TimeLimitedWarranty(sellingDate, warrantySpan);

            //SoldArticle goods = new SoldArticle(moneyBack, warranty);
            //  Offer money back
            //  Offer repair

            //SoldArticle goods = new SoldArticle(VoidWarranty.Instance, warranty);
            // Offer repair
            IWarranty   warranty = new LifetimeWarranty(sellingDate);
            SoldArticle goods    = new SoldArticle(warranty, warranty);

            ClaimWarrenty(goods);
        }