Object relationship: Difference between revisions

From Rice Wiki
No edit summary
No edit summary
 
Line 1: Line 1:
= 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.
In [[OOP]], interrelated objects are composed together for complex functionality. This page describes concepts that relate one object to another.



Latest revision as of 02:21, 10 August 2024

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