Exemplo n.º 1
0
        public void Visit(RealEstateOwner owner)
        {
            Console.WriteLine("Tax visitor is doing some calculations...");
            Thread.Sleep(1000);

            foreach (var property in owner.Properties)
            {
                if (property.GetType().Name.Equals("Monastery"))
                {
                    owner.CreditAmount += 0.00M;
                }
                else if (property.GetType().Name.Equals("Castle"))
                {
                    if (property.AreaSquareMetters >= 520 && property.AreaSquareMetters <= 2080)
                    {
                        owner.CreditAmount += 1260.00M;
                    }
                    else if (property.AreaSquareMetters > 2080)
                    {
                        owner.CreditAmount += 15060.00M;
                    }
                    else
                    {
                        owner.CreditAmount += (property.AreaSquareMetters * 1.20M);
                    }
                }
                else
                {
                    owner.CreditAmount += (property.AreaSquareMetters * 0.80M);
                }
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var monastery = new Monastery(300.00M, 300000.00M);
            var castle = new Castle(621.00M, 12000000.00M);
            var house = new House(128.00M, 150000.00M);

            var owner = new RealEstateOwner("Rahzel");

            owner.BuyProperty(monastery);
            owner.BuyProperty(castle);
            owner.BuyProperty(house);

            Console.WriteLine("Credit amount before visit: {0} $.{1}", owner.CreditAmount, Environment.NewLine);

            owner.Accept(new TaxVisitor());
            Console.WriteLine("Credit amount on first visit: {0} $.{1}", owner.CreditAmount, Environment.NewLine);

            castle.AreaSquareMetters += 2000.00M;

            owner.Accept(new TaxVisitor());
            Console.WriteLine("Credit amount on second visit after castle expansion: {0} $.{1}", owner.CreditAmount, Environment.NewLine);
        }