Object relationship: Difference between revisions

From Rice Wiki
(Created page with "In OOP, interrelated objects are composed together for complex functionality. This page describes concepts that relate one object to another. = Inheritance = = Composition = = Aggregation = Unlike")
 
No edit summary
 
(One intermediate revision by the same user not shown)
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.


= Inheritance =
= 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 =
= Composition =
Unlike [[Object relationship#Inheritance|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.<syntaxhighlight lang="c++">
class Owner
{
    Extended ext;
  public:
    Owner() {
        ext = Extended();
    }
};
</syntaxhighlight>


= Aggregation =
= Aggregation =
Unlike
Similar to [[Object relationship#Composition|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

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