Aggregation

📚 Gaddis (Ch. 14.7)

Aggregation of Objects

  • Aggregation: an object of one class is used as an attribute in another class
  • Often called composition
  • Creates the “has a” relationship

Large example in Chapter 14 of the Gaddis textbook.

    Instructor
    Textbook
    Course

Example

class Tool{
    public:
        [...] // interface not shown for brevity
    private:
        std::string name;
        double      weight;
};

class ToolBox{
    public:
        [...] // interface not shown for brevity
    private:
        Tool inventory[1024]; // aggregation of "Tool" objects
};

Aggregation