When one class have as method parameter pointer(or reference, or object) to other class, in UML it is reflected as association or aggregation, with diamond, or have some specific notation?
4 Answers
As explained by other guys, you should use dependency and not any form of association (aggregation and composition).
A dependency means that the target element is required for the specification or implementation of the source element.
However, there are many different types of dependencies. The type of dependency can be specified by keywords and stereotypes. In your case you should use a dependency
with keyword <<use>>
:
To explain <<use>>
I quote a part of the book UML 2 and The Unified Process from page 196:
This dependency (usage) is generated by any of the following cases:
1- An operation of class A needs a parameter of class B
2- An operation of class A returns a value of class B
3- An operation of class A uses an object of class B somewhere in its implementation but not as an attribute.
P.S: Other keywords/stereotypes a dependency can have are call, create, derive, instantiate, permit, realize, refine and trace.

- 5,856
- 2
- 25
- 37
-
How do you know it's *use* in this case? – SomeWittyUsername Mar 24 '13 at 16:31
-
@icepack well that is the definition of `< – jurgenreza Mar 24 '13 at 17:07
-
Nothing in the question limits it to this type. It can be call or trace, for example – SomeWittyUsername Mar 24 '13 at 22:17
-
@icepack Absolutely not. Call and trace dependencies have totally different meanings. Read the UML specification: "*The call relationship is defined and specified from one operation to another operation, so that the source element calls the target operation.*" "*The trace relationship means that the dependent element leads to the independent to trace semantic dependencies (e.g., from a use case to a class).*" – jurgenreza Mar 24 '13 at 23:17
-
I disagree. Nothing in the question indicates the limits of usage model. The pointer can be, for example, a function pointer that the receiver can invoke. A very visual explanation can be found here: http://www.uml-diagrams.org/dependency.html – SomeWittyUsername Mar 25 '13 at 06:31
-
1@icepack I think we are not on the same page here. "when one class has as a method parameter pointer to another class" is the title of the question. "An operation of class A needs a parameter of class B" clearly matches it. I don't know what you are talking about when suggesting trace or call which have obviously different meanings. – jurgenreza Mar 25 '13 at 13:42
-
"*when one class has as a method parameter pointer to another class*" doesn't indicate in any way the type of dependency or the usage of the pointer. It's just a technical description of the interface. – SomeWittyUsername Mar 25 '13 at 14:05
-
Nice and well argumented answer. The only concern I have is about pointers speicifically. Because you could very well use a pointer argument without knowing anything about the class, except that it's a class. Maybe this is a subtle difference that is too language specific for UML, and would best be solved with a dedicated stereotype... – Christophe Mar 16 '22 at 22:05
-
And UML 2.5.1 nowadays is clearer: "*A Usage is a Dependency in which one NamedElement requires another NamedElement for its full implementation or operation. The Usage does not specify how the client uses the supplier other than the fact that the supplier **is used by the definition** or implementation of the client.*" – Christophe Mar 16 '22 at 22:12
What you need is not an association (nor an aggregation or a composition that are specific associations) because an association refers to an attribute of your ClassA being of type ClassB.
Here, for a method parameter, you can use a dependency arrow between your classes (dashed arrow). It is a very general relationship that should fit your purpose.
See for example here for an explanation: http://martinfowler.com/bliki/DependencyAndAssociation.html

- 1,989
- 14
- 18
-
Good point, since the reference seems to be transient rather than static, dependency would fit better – SomeWittyUsername Mar 24 '13 at 09:13
Association is a link of one class to another, hence pointer/reference describe an association.
Aggregation/Composition describe the type of the association and as such are actually a detalization of it (but there are types of association that aren't aggregation/composition).
Whether or not you want to use aggregation or association depends on the level of details that you want to show in your diagram.
Given the question description, the connection is of weaker kind since it's not a static link but rather a transient one. In this case more appropriate would be to use the Dependency relation rather than association.

- 18,025
- 3
- 42
- 85
"The usage dependency does not specify how the client uses the supplier other than the fact that the supplier is used by the definition or implementation of the client. For example, it could mean that some method(s) within a (client) class uses objects (e.g. parameters) of the another (supplier) class . "

- 120
- 2
- 4