Inheritance: Item, Visitable
 public double Visit(Liquor liquorItem)
 {
     Console.WriteLine("Liquor item: Pric with Tax");
     return((liquorItem.getPrice() * .18) + liquorItem.getPrice());
 }
 public double visit(Liquor item)
 {
     Debug.Log ("Liquor item: Price with Tax");
     return item.price * 1.18f;
 }
        void OnEnable()
        {
            Debug.Log ("------------------");
            Debug.Log ("VISITOR DESIGN PATTERN");

            // testing the pattern:

            TaxVisitor taxCalc = new TaxVisitor();
            TaxHolidayVisitor taxHolidayCalc = new TaxHolidayVisitor();

            Necessity milk = new Necessity(3.25);
            Liquor vodka = new Liquor(11.99);
            Tobacco cigars = new Tobacco(19.99);

            double milkPrice = milk.Accept(taxCalc);
            double milkPriceHoliday = milk.Accept(taxHolidayCalc);
            Debug.Log ("Milk costs: " + milkPrice.ToString() + ", Holiday Price: " + milkPriceHoliday.ToString());

            double vodkaPrice = vodka.Accept(taxCalc);
            double vodkaHolidayPrice = vodka.Accept(taxHolidayCalc);
            Debug.Log ("Vodka costs: " + vodkaPrice.ToString() + ", Holiday Price: " + vodkaHolidayPrice.ToString());

            double cigarsPrice = cigars.Accept(taxCalc);
            double cigarsPriceHoliday = cigars.Accept(taxHolidayCalc);
            Debug.Log ("Cigars cost: " + cigarsPrice.ToString() + ", Holiday Price: " + cigarsPriceHoliday.ToString());
        }
Esempio n. 4
0
 public double visit(Liquor item)
 {
     Debug.Log("Liquor item: Price with Tax");
     return(item.price * 1.18f);
 }