## 26.6 The COMPOSITE Pattern (cont.)

- Functions of the composite class must be applied to all primitives, then combine the results
- E.g., compute the price of a bundle:

  >     double Bundle::get_unit_price() const
  >     {
  >        double price = 0;
  >        for (int i = 0; i < items.size(); i++)
  >        {
  >           price = price +
  >              ( items[i]->get_unit_price()
  >                 * items[i]->get_quantity() );
  >        }
  >        return price;
  >     }

prev |top |next