Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UML association understanding problem

Tags:

uml

I've been using UML for a while and I've read few articles, books, forums about it but I still don't REALLY understand when two classes should be connected with association line (a simple line or arrow (or are these not the same?)). I'll provide three examples - can you tell me which one will cause the two classes to be in this relationship?

1.

//a field of OtherClass
    public class MainClass
    {
        private OtherClass other;
    }

2.

//method argument
    public class MainClass
    {
        public void Action(OtherClass other)
        { }
    }

3.

//method return value
    public class MainClass
    {
        public OtherClass Action()
        { }
    }

4.

//used inside a method
    public class MainClass
    {
        private Something something;

        public void Action()
        {
            OtherClass other = something.GetOtherClass();
        }
    }
like image 222
agnieszka Avatar asked Jul 17 '09 09:07

agnieszka


People also ask

What do you understand by the term association in UML?

In UML models, an association is a relationship between two classifiers, such as classes or use cases, that describes the reasons for the relationship and the rules that govern the relationship.

How is an association shown in a UML diagram?

Association can be represented by a line between these classes with an arrow indicating the navigation direction. In case an arrow is on both sides, the association is known as a bidirectional association. We can also indicate the behavior of an object in an association (i.e., the role of an object) using role names.

What are the different types of association in UML?

An association can be categorized into four types of associations, i.e., bi-directional, unidirectional, aggregation (composition aggregation), and reflexive, such that an aggregation is a special form of association and composition is a special form of aggregation.

Is it possible for there to be more than one association between any two classes?

You can create as many associations between classes as you need. There is no limit. You should add association-end names to clarify the purpose of each association, since without them the model will just not make much sense. However, in your example you have one association class and a normal association.


1 Answers

First of all an arrow represents navigability of the association. Single arrow means unidirectional relation, in this case only the source class knows about the target class. Arrow on both ends means bidirectional relation, where both classes know about each other. If no arrows are present the association can be either bidirectional by default or suppressed for the sake of readability. In practice you should draw arrows only when you want to emphasize the direction of the association.

When it comes to your second question, only the first case describes an (unidirectional) association between MainClass and OtherClass. Neither arguments nor return values imply association in the UML sense (although both imply dependency). In the last example there is an association between MainClass and Something class through the something attribute. As a rule of thumb you should look for associations in attributes.

Please note that there is a concept of dependency in UML and it is represented by a dashed line.

Pozdrowienia!

like image 135
Adam Byrtek Avatar answered Dec 01 '22 08:12

Adam Byrtek