Object relationship

From Rice Wiki
Revision as of 02:21, 10 August 2024 by Rice (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

IMPORTANT NOTE: This page may be wrong since I am confused.

In OOP, interrelated objects are composed together for complex functionality. This page describes concepts that relate one object to another.

Inheritance

Implementation inheritance extends the implementation of a parent class with a child class that inherit the members of the parent class while adding/overriding certain members.

Composition

Unlike inheritance, which directly extends a parent object, composition owns the object whose functionality it wishes to extend. This solves many of the issues of inheritance.

class Owner
{
    Extended ext;

  public:
    Owner() {
        ext = Extended();
    }
};

Aggregation

Similar to composition, aggregation involves an object "having" another object. The difference between the two lies in that composition focuses on a parent-child relationship, whereas Aggregation