badger5000
badger5000

Reputation: 660

terminology for class objects related by composition

class C {
private:
    int j;
};

class B {
private:
    C c;
};

class A {
private:
    B b;
};

A a;

I'm wondering what the correct terminology for a composition hierarchy in C++:

I'd be tempted to use terms like child, parent, root, base, sub-object, etc, but these seem to usually refer to an inheritance relationship or are ambiguous. "Contained object" seems OK (albeit a bit clunky), but in the other direction I can't say "container" (already refers to a vector, map etc). Is there any succinct and conventional way to describe the relationships?

Upvotes: 2

Views: 110

Answers (1)

Jonathan Mee
Jonathan Mee

Reputation: 38939

This is taken from the exelent synopsis of: https://en.wikipedia.org/wiki/Has-a

What is b to c?

c is a "meronym" or "constituent" of b. This is a "part-of" relationship.

What is c to b?

b is a "member" of c or b is "composed" of c. This is a "has-a" relationship.

What is a to c, and vice-versa?

Object-oriented terms for talking about jumping two levels of hierarchy are incongruent, though "grandchild", "grandparent", or "intermediate class" may be thrown around.

In this particular case it would be fair to say that c is a "meronym of a's member" or "constituent of a's member". And that "a's member is composed of c".

But in either case you're really just trying to describe that hierarchy.

Upvotes: 2

Related Questions