## 26.7 Case Study: Putting Patterns to Work (cont.)

- Make the strategy object available to `Invoice::print`:

  >     void Invoice::print(InvoiceFormatter& formatter)
  >     {
  >        print_header("I N V O I C E");
  >        print_string("Description", true);
  >        print_string("Unit Price", false);
  >        print_string("Qty", false);
  >        print_string("Total Price", false);

  >        double amount_due = 0;
  >        for (ItemIterator iter = inv.create_iterator();
  >           !iter.is_done(); iter.next())
  >        {
  >           Item* it = iter.get();
  >           print_string(it->get_description(), true);
  >           print_number(it->get_unit_price(), 2);
  >           print_number(it->get_quantity(), 0);
  >           print_number(it->get_total_price(), 2);
  >           amount_due = amount_due + it->get_total_price();
  >        }

  >        print_footer("AMOUNT DUE:", amount_due);
  >     }

prev |top |next