示例#1
0
        static void ClaimWarranty(SoldArticle article)
        {
            var now = DateTime.Now;

            //if (article.MoneyBackGuatrantee.IsValidOn(now))
            //{
            //    Console.WriteLine("Offer money back.");
            //}

            //if (article.ExpressWarranty.IsValidOn(now))
            //{
            //    Console.WriteLine("Offer repair");
            //}
            article.MoneyBackGuatrantee.Claim(now, () => Console.WriteLine("Offer money back."));
            article.ExpressWarranty.Claim(now, () => Console.WriteLine("Offer repair"));
        }
示例#2
0
        static void Main2()
        {
            var sellingDate   = new DateTime(2016, 8, 9);
            var moneyBackSpan = TimeSpan.FromDays(30);
            var warrantySpan  = TimeSpan.FromDays(365);

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

            // var noMoneyBack = new VoidWarranty();

            //var goods = new SoldArticle(noMoneyBack, warranty);

            var goods = new SoldArticle(VoidWarranty.Instance, warranty);

            ClaimWarranty(goods);
            Console.ReadLine();
        }
示例#3
0
文件: Program.cs 项目: john4ani/OOP
        static void ClaimWarranty(SoldArticle article, bool inGoodCondition, bool isBroken)
        {
            //#Bad code, highlighting the probelem

            //var now = DateTime.Now;
            //if (inGoodCondition && !isBroken &&
            //    article.MoneyBackGuatrantee != null &&
            //    article.MoneyBackGuatrantee.IsValidOn(now))
            //{
            //    Console.WriteLine("Offer money back.");
            //}

            //if (isBroken && article.ExpressWarranty != null &&
            //    article.ExpressWarranty.IsValidOn(now))
            //{
            //    Console.WriteLine("Offer repair");
            //}
        }