Reputation: 660
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++:
b
to c
, and vice-versa?a
to c
, and vice-versa?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
Reputation: 38939
This is taken from the exelent synopsis of: https://en.wikipedia.org/wiki/Has-a
b
to c
?c
is a "meronym" or "constituent" of b
. This is a "part-of" relationship.
c
to b
?b
is a "member" of c
or b
is "composed" of c
. This is a "has-a" relationship.
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