In C++ since private inheritance is not considered as an is-a
relationship, how is it supposed to be shown in a class diagram and if it is shown as a has-a
relationship then how can it be differentiated between a composition and a private inheritance?
Asked
Active
Viewed 2,176 times
13

ahj
- 745
- 1
- 6
- 13
-
5This is an excellent question. The problem is that private inheritance is an oxymoron, which is why it is not part of the UML dictionary. I would show it as has-a with a remark stating that it's privately inherited. Another choice is to refactor your design to avoid private inheritance: the cases when you must have it are few and far between, so good chances are that a plain has-a would work just fine. – Sergey Kalinichenko Feb 23 '12 at 14:57
1 Answers
4
It should be a Composition relationship (solid black diamond on the subclass side), because:
- Private inheritance means "implemented in terms of" but in this regard it can be simply treated the same as "has a" relationship.
- An instance of the subclass clearly owns the base calss part of the object, and the ownership is not shared with any other objects.

H Xu
- 305
- 1
- 8