Inheritance: Item, Visitable
 public double Visit(Necessity necessityItem)
 {
     Console.WriteLine("Necessity item: Pric with Necessity");
     return((necessityItem.getPrice() * 0) + necessityItem.getPrice());
 }
 public double visit(Necessity item)
 {
     Debug.Log ("Necessity item: Price with Tax");
     return item.price;
 }
        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());
        }
Exemplo n.º 4
0
 public double visit(Necessity item)
 {
     Debug.Log("Necessity item: Price with Tax");
     return(item.price);
 }