8

I want to draw a UML diagram of my program. Class Barney has a method Yabadaba(Doo d) which takes a parameter of type Doo.

How do I represent that class Doo is used in class Barney in my UML diagram?

  • 3
    What type of UML-diagram are you creating? Sequence, class, state, activity, ...? – Kenneth Jul 16 '13 at 20:28
  • @Kenneth class. – CodyBugstein Jul 22 '13 at 21:39
6

Smells like a homework. Oh well.

I want to draw a UML diagram of my program.

What type of UML diagram? Class, sequence, collaboration? You need to learn to be precise and clear when asking questions.

With that said, I am going to assume you meant to ask for a class diagram (and my answer will be based off that assumption.)

Class Barney has a method Yabadaba(Doo d) which takes a parameter of type Doo.

How do I represent that class Doo is used in class Barney in my UML diagram?

You represent it by having a class artifact for Barney, in a class diagram, and with a method that takes the type (Doo) in question

enter image description here

If, the class Barney has a member field of type Doo, in addition to a method that takes an instance of Doo, then, you will have Barney with a Doo field on it.

enter image description here

Either that, or as an aggregation/association of some type. This example would show a composition of Barney with Doo.

enter image description here

What association/method you use to represent this, that depends on what you want to do. And for that, well, the solution is to read the manual. Hope it helps.

=== edit ===

btw, these images were created with the yuml.me online drawing tool.

  • It's not homework at all, but Thanks!! – CodyBugstein Jul 22 '13 at 21:36
  • 1
    I believe it is required to supply a parameter name, not just a type (in UML 2.5). – Alan Dec 22 '16 at 20:11
7

At the very least, you want a dependency relationship from class Barney to class Doo:

Dependency

If class Barney maintains an instance of Doo at some point in its life, then the relationship is stronger and becomes an association relationship:

Association

The association relationship can be made even strong by adding a direction.

You can also consider multiplicity, which is the number of elements. This is most useful for if the element is optional or for composition/aggregation relationships. You may also decide that it may not be appropriate to include the Doo class in your model, in which case you can simply indicate the method exists in Barney.

-3

The Class Barney have not any relationship, but next class Barney you put enumeration class Doo with the Doo property.

  • 4
    Huh? Could you explain that with a picture or diagram? You may find asciiflow.com useful for creating an ascii-art diagram for this. – user40980 Sep 14 '14 at 1:00

protected by gnat Feb 20 '17 at 21:07

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.