There is a class A, an IB interface, and a class B that implements an IB interface. Class A has a field of type IB. During program execution, the value of this field becomes an instance of class B. How to draw a class diagram for this situation? Is there a “composition” relationship between A and IB, and is composition a relationship between A and B, or just a dependency?
It depends on the language and/or the semantics that you want to give to your construct.
In a language with reference based classes like java:
B could always be shared and therefore continue to live after the death of the A object. This is in contradiction with the composition in UML. In a language with value based classes like C++:
unique_ptr<IB> you would express a composition. Other pointers might allow sharing of objects, so the normal association would be a better representation. But UML is not a programming language. It's a modelling language. So you should express in the model the semantic that you want. If IB objects are not expected to be shared, and should not outlive A, then composition appropriate shows this intent. If not, remain open.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With