10

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 4

13

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>>:

enter image description here

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.

Sign up to request clarification or add additional context in comments.

9 Comments

How do you know it's use in this case?
@icepack well that is the definition of <<use>>. See the part I added to my answer from UML 2 and the Unified Process book.
Nothing in the question limits it to this type. It can be call or trace, for example
@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)."
@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.
|
10

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 Comment

Good point, since the reference seems to be transient rather than static, dependency would fit better
0

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.

Comments

-1

"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 . "

ref: enter link description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.