previous | start | next

## Implementing Associations

- You use pointers in three circumstances.
  - For a "1 : 0 or 1" relationship
  - For object sharing
  - For polymorphism, to refer to an object that may belong to a base class or a derived class.
- Examples:
  - Since multiple bank accounts could share the same owner, it makes sense to use a pointer.

    >     class Bank Account
    >     {
    >        ...
    >     private:
    >        Person* owner;
    >     };

  - A vehicle has multiple tires, but a tire can only be part of a single vehicle.

    >     class Vehicle
    >     {
    >        ...
    >     private:
    >        vector<Tire> tires;
    >     };

previous | start | next