kbb5268
kbb5268

Reputation: 35

Is my UML Diagram Correct for the attached code?

My professor gave us this program but did not explain UML to us at all and I am wondering if I have made this diagram correctly.

CODE:

package p1;
public class MyProg {
    static int i = 5;
    private Integer j = new Integer(10);
    protected double k = 2.5;
    public MyProg() {}

    public static void main(String[] args) {  
        MyProg mp = new MyProg();  
    }

    void m1(){
        System.out.println("Hello World!");
    }

    void m1(String str, int n){
        for(int k = 0; k < n; k++)
            System.out.println(str);
    }

    public static int getI(){   
        return MyProg.i;  
    }

    protected Integer getJ(){   
        return new Integer(j);
    }

    double getK(){  
       return new Double(k);   
    }
}

enter image description here

Upvotes: 1

Views: 563

Answers (3)

I've never been much for being too obsessive about details of UML myself (I've definitely seen design meetings that descended into discussions of the finer points of UML rather than about the design itself), but a few minor points:

  • You usually wouldn't want to include private variables, methods, etc. on a class diagram because that's an implementation detail (not a design detail). Edit: This point probably depends somewhat on the purpose of your diagram - some people would argue that it's acceptable to include those under certain circumstances (e.g. if your primary purpose is to communicate your implementation rather than your design).
  • A few of these methods (e.g. double getK()) are missing access modifiers. While it's technically syntactically legal to rely on the defaults, it's always better to be explicit about your intent.

Upvotes: 1

Ister
Ister

Reputation: 6328

On your diagram:

  • As already mentioned i and j are not string
  • in main operation args parameter is some sort of array so you are missing the multiplicity indicator (asterisk in square brackets before closing round bracket). So the line should look like + main(in args: String[*]). Of course underscored
  • in m1 operation n should have unspecified type
  • initial values should be specified as already mentioned in comments
  • you can use standard stereotype <> at MyProg operation to mark it as a constructor. Some books suggest not to model constructor unless it's non-standard (i.e. requires some parameters)
  • I would be very careful about in vs inout indicator for parameters. In Java the objects are passed through reference by default which means the parameter is inout, not in. In C++ it's the contrary situation, a parameter is passed through value i.e. it's in.

Upvotes: 2

qwerty_so
qwerty_so

Reputation: 36333

Would be nice to paste all answers in a single one...

  • In the program you use Integer, String, Double (as being classes, I guess) and sometimes mix int while in your class diagram you use all lower case (being primitives) and always integer. That should be aligned.

Upvotes: 0

Related Questions