Avatar billede fredand Forsker
20. januar 2003 - 10:36 Der er 10 kommentarer og
1 løsning

UML-question!

Hello!

I got a question about relations in UML.

The question is illustrated with a image. You can take a look at it at:

http://medlem.spray.se/fredand44/ques.html

Best regards

Fredrik
Avatar billede arne_v Ekspert
20. januar 2003 - 10:49 #1
I would call code A for aggregation and
code B for association.
Avatar billede fredand Forsker
20. januar 2003 - 10:57 #2
Hello!

But could you say that image 1 describes code B and image 2 describes code A, or the opposite, or not at all?

/Fredrik
Avatar billede arne_v Ekspert
20. januar 2003 - 11:13 #3
code A = aggregation
code B = association
image 1 = aggregation
image 2 = composition

so image 1 matches code A
Avatar billede fredand Forsker
20. januar 2003 - 12:28 #4
Hello!

Could you give me a example in code for composition, aggreagation and association?

I would say:
//Class that creates and keeps a reference to an other class = Composition
public class Class1
{
  Class2 class2;

  public Class1()
  {
    class2 = new Class2();
  }

}

----------------------
//Class that generates an other class but not keeps a reference = Aggregation
public class Class1
{

  public Class1()
  {
    method( new Class2() );
  }

}
-------------------------
//Class thats gets a reference to an other class but the other class is created somewhere else = Association.
public class Class1
{
  ClassX classX 

  public Class1(ClassX cX)
  {
    classX = cX;
  }

}

Or am I wrong????

Best regards

Fredrik
Avatar billede arne_v Ekspert
20. januar 2003 - 15:16 #5
You are at least partly rigth.

A composition means that X owns Y.

public class X {
    private Y y;
    public X() {
        y = new Y();
    }
}

Noone else can use y.

An aggregation means that X has a reference to Y.

Example:

public class X {
    private Y y;
    public X(Y y) {
        this.y = y;
    }
}

Another class can also use y.

Association just means that X uses Y.

It can be composition or aggregation.

It can also just be other use.
Avatar billede arne_v Ekspert
29. januar 2003 - 22:48 #6
Are you satisfied with the answer ?
Avatar billede fredand Forsker
30. januar 2003 - 11:56 #7
Hello Amigo!

I am strugling with this but please hang on! I may add som question if that is OK.

Best regards
Fredrik
Avatar billede arne_v Ekspert
30. januar 2003 - 12:08 #8
OK
Avatar billede fredand Forsker
02. april 2003 - 11:22 #9
Hello Arne!

I have made a new table to straighten this out at:

http://medlem.spray.se/fredand44/umltable.html

I would be most thankful if you could take a look at it and se if this is correct.

Best regards
Fredrik
Avatar billede arne_v Ekspert
02. april 2003 - 11:32 #10
It looks OK to me.

I can not guarantee that it is the ultimate truth.

But you will be able to argue your case.
Avatar billede fredand Forsker
02. april 2003 - 11:44 #11
Thanx mate!
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester