How to show class contained as attribute in another class

Hi,

I am a beginner with UML, so please forgive the basic nature of this question.

I wish to depict the following common situation on a UML 2 class diagram:

classA {}

classB
{
  private: classA myIdentifier;
}

My question is: on the diagram, do I add an attribute to ClassB and give this the type ClassA or do I omit the attribute and put both classes on the diagram with an association between them? Or do I do both?

What is the preferred (correct?) way of showing this?

Any help or advice would be very much appreciated.

Best wishes, Patrick Skelton

Hi Patrick,

Please see if the image attached is what you are looking for.

Best regards,
Jick
uml-questions-FM2490s.png