Reputation: 169
I wanted to know how i can design a uml class diagram or uml diagrams in General of These Java classes:
public class A{
private A parent;
private B[] b = new B[3];
protected int i;
private Vector<C> c; //container for objects of class C
}
public class B {
}
public class C {
private A owner;
public A getOwner() {return owner;}
}
Maybe someone who has the Software can post an example how an class diagram in uml can look lie with These Java classes.
Upvotes: 0
Views: 3072
Reputation:
Something like this?
EDIT0: and a simple object diagram sample
Edit1:
explanation:
in object diagram you should specify the value of each variable, here the i=1990
is an example, it could be any number.
A a=new new A();
a.setI(1990);
as you see, there are two instances of class A
named a
and a1
.
A a=new A();
A a1=new A();
The a1
reference has no value for variable c, so it's null
.
class B
doesn't have anything(attribute) here.
in class A
, the b variable is a array of class B
, so a
variable has two B
references(b0
,b1
) and a null
value.
B b0=new B();
B b1=new B();
a.setB(new B[]{b0,b1,null});
////
B b2=new B();
a1.setB(new B[]{null,null,b2});
and about the :C
and :Vector<C>
, why doesn't it have a name lie a1
or b0
? because there is no need for pointer(reference) for the class, so it doesn't need a pointer, in other word an object from Vector<>
and two objects from C
are created and passed to the host class A
.
a.setC(new Vector<C>());
a.getC().put(new C(a));
a.getC().put(new C(a));
and about the owner
in C
class, assume that the owner is set during the object creation by constructor, or has set by a indirect reference (using A.c
).
I hope I could give some hand dude.
Software: UMLet
Upvotes: 1