Sign up ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Let's say I have BaseA and BaseB classes. BaseB can have to several references of BaseA instances. Now, we have two other classes, DerivedA and DerivedB that respectively inherit from BaseA and BaseB.

enter image description here

How can I show in such a diagram that DerivedB should only store instances of DerivedA and not instances of BaseA? It seemed pretty simple before I tried to draw it, but now I'm confused. One obvious answer would be "redesign your code"; if there is no alternative, I will probably try to do so.

share|improve this question
make the type in derived B as has many of DerivedA ? does not matter that Derived A's base class is BaseA. As far as DerivedB is concrned it has variables of type 'DerivedA' –  tgkprog Apr 19 '13 at 12:49
@tgkprog Well, since I am using Python, If I feed DerivedB some BaseA, those instances will not automagically be converted to DerivedA. When I think about it again, it may be more a "contract" with the programmer than a strict design... –  Morwenn Apr 19 '13 at 12:55
@Morwenn: I am not a Python export, but in other languages you would just create BaseA as an abstract base class, so you cannot have any instances of BaseA which are not also a "DerivedA". Perhaps this concept is similar? –  Doc Brown Apr 19 '13 at 13:13
@DocBrown Hum, I never had to use this module before, I will have a look :) –  Morwenn Apr 19 '13 at 13:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.