How do I make an aggregation relationship in Java

A

Anonymous

I have two classes. Player.java and Team.java
I want to make Player a member of Team.

how do you do this?
I tried putting Player p1 = new Player(); in Team but Visual Paradigm
(when asked to generate a class diagram from java code) did not show
an aggregation relationship in the class diagram (no line with a
diamond shaped end)
anyone know how to do it properly?
if visual paradigm is wrong any suggestions on a new program to use?
 
C

Chris Smith

Anonymous said:
I have two classes. Player.java and Team.java
I want to make Player a member of Team.

how do you do this?
I tried putting Player p1 = new Player(); in Team but Visual Paradigm
(when asked to generate a class diagram from java code) did not show
an aggregation relationship in the class diagram (no line with a
diamond shaped end)
anyone know how to do it properly?

There is no distinction in Java between aggregation and composition.
Which you have depends on how you use the member. Reverse engineering
to UML is not going to catch this, regardless of your tool. What you
need to do is leave the code alone, and modify the UML diagram to
express your intention.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
J

Jeffrey Spoon

Anonymous said:
I have two classes. Player.java and Team.java
I want to make Player a member of Team.

how do you do this?
I tried putting Player p1 = new Player(); in Team but Visual Paradigm
(when asked to generate a class diagram from java code) did not show
an aggregation relationship in the class diagram (no line with a
diamond shaped end)
anyone know how to do it properly?
if visual paradigm is wrong any suggestions on a new program to use?

Try this: http://www.dcs.napier.ac.uk/~kab/jeRome/jeRome.html
 
J

Jim

Anonymous said:
I have two classes. Player.java and Team.java
I want to make Player a member of Team.

how do you do this?
I tried putting Player p1 = new Player(); in Team but Visual Paradigm
(when asked to generate a class diagram from java code) did not show
an aggregation relationship in the class diagram (no line with a
diamond shaped end)
anyone know how to do it properly?
if visual paradigm is wrong any suggestions on a new program to use?

Is Player an attribute of Team in your code?

You need to write something like

public class Team {
private Player p1; // p1 is an attribute of Team

// constructor
public Team() { p1 = new Player(); }
}

or you won't get an association. If you have written

public class Team {

// constructor
public Team() {}
public void someMethod() {
Player p1 = new Player(); // Just a local variable!
}
}

you do not have an association, only a dependency.

You still may not get the diamond. Aggregations are usually a
collection of some object. So you can code something like this

public class Team {
private ArrayList thePlayers = new ArrayList();

// constructor
public Team() {}
public void someMethod() {
thePlayers.add(new Player());
}
}

thePlayers is an aggregate of Players.

Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top