What does var : Var mean in a uml digram and how would I write it in java?

Viewed 67

So I have an assignment where I have to write Java code from a UML diagram and am not able to understand a part from the UML diagram.

enter image description here

what does - name : Name and - startDate : Date mean?

2 Answers

The compartment below the name of a class lists its attributes. The first char is the visibility which (in this case) are - for private and + for public attributes. It follows the attribute's name and optionally separated by a colon the type.

Now, the type is just a string and it could be anything. It is likelely that the types correspond to the classes with the same name but from just this diagram it's not for sure. It would be different if instead you had associations with role names. In that case it would be unambiguous.

The next compartment below lists operations. Enclosed in brackets you have the paramenters as name:type. Some types are predefined primitives like int. Others are again class names with the same issue as above. Now in that case you would use dependencies to clarify the relation since you can not otherwise denote which classes you refer as a parameter. Here it would be desireable to have a (XML) model rather than just the diagram.

Just my judgement: who ever created that class diagram should go and take a fresh lesson...

P.S. As to the title of your question: I can't help much with Java but most C-like languages (which Java is one of) you have variable declarations that denote name and type. For classes you would create instances. Somehow. Ask a Java guy or consult your next Java manual ;-)

qwerty_so has answered the question for what the diagram was asking and my answer is how to write it in java.

So basically the diagram means this:

private Name name;

and

private startDate Date;
Related