0

I am just starting with UML (StarUML 5) so please excuse this really basic question.

Let's say a Person has multiple Characteristics, each of which has a Name and a Value. (This is just to keep things simple.) Suppose I create the Characteristic class accordingly.

I want to generate Java class Person with a property something like ArrayList(Characteristic).

Should I add an attribute to the Person class like ArrayList(Characteristic), or should I just use an Aggregation relationship between Person and Characteristic and specify the multiplicity as 0..* ?

On the first (ArrayList) approach I don't even model the multiplicity. On the second (Aggregation) approach the Java code creates a property in Person of type Characteristic but not a "List-like" property, i.e. it ignores the multiplicity in the diagram.

Thank you.

Jeff Loughlin
  • 4,134
  • 2
  • 30
  • 47
Aharon
  • 1
  • 1

2 Answers2

1

I agree with Dave, this is a composition, a kind of UML association. Setting the composition as Ordered and not unique allows to generate the Java attribute as a List. It means you have a composition at the design level and a List at the implementation level. That's the code generator - or you if you don't use code generation - which correctly translates the UML diagram.

Here's what I would design in your case and the Java code I generated (feel free to fork):

public class Person
{
    /**
     * <!-- begin-user-doc -->
     * <!--  end-user-doc  -->
     * @generated
     * @ordered
     */

    public List<Characteristic> characteristic;

    /**
     * <!-- begin-user-doc -->
     * <!--  end-user-doc  -->
     * @generated
     */
    public Person(){
        super();
    }    
}

Notice you can import StarUML projects in GenMyModel if you'd like to quickly design generate online.

benw2
  • 65
  • 4
0

This sounds like a composition relationship to me. In my opinion you're better off with the second approach using Aggregation/Composition. Here is an interesting read on one take on Attribute vs Association. Regarding the failure of StarUML to implement the relationship correctly, you might be better off just implementing the List yourself.

DaveH
  • 534
  • 1
  • 7
  • 17