public static void Test() { /* * Scenario: we've had a concrete credit card class and we needed new methods * for air travel and food supplies cashback calculation. Instead of adding to the interface, * and then implementing them in each sub-class, we simply defined only 1 method * in the CreditCard interface - accept() which takes on a visitor who supplies * the functionality we need. Thus, we had to violate the OCP in the CreditCard interface * and implementations **only** once, and have opened our hierarchy to future behavioral extensions. */ var bronze = new BronzeCreditCard(); var silver = new SilverCreditCard(); var gold = new GoldCreditCard(); // we only need to create 1 visitor, which can interact with our 3 objects var airtraverlVisitor = new AirtravelOfferVisitor(); bronze.Accept(airtraverlVisitor); silver.Accept(airtraverlVisitor); gold.Accept(airtraverlVisitor); var foodVisitor = new FoodOfferVisitor(); gold.Accept(foodVisitor); }
public void VisitSilverCreditCard(SilverCreditCard card) { Console.WriteLine("The Silver credit card has 0.3% cashback for food supplies."); }
public void VisitSilverCreditCard(SilverCreditCard card) { Console.WriteLine("The Silver credit card has 2.5% cashback on air-travel purchases."); }