Monday, May 24, 2010

Examine the Java program and draw the associated class diagram including methods and attributes.?

Examine the Java program and draw the associated class diagram including methods and attributes.





public interface InterfaceA {


void method1();


}


public class ClassA implements InterfaceA {


public ClassA() {


//contents of ClassA()


}


public void method1() {


//contents of method1


}


private char c;


private int x;


public int y;


}


public class ClassB implements InterfaceA {


public void method1() {


//contents of method1


}


private ClassC a;


}


public class ClassC {


private int myMethod() {


// contents of myMethod


}


public void cMethod() {


//contents of cMethod


}


public class ClassD extends ClassB {


//contents of ClassD


}

Examine the Java program and draw the associated class diagram including methods and attributes.?
This is a little hard to draw without monospaced text, so I'll try to describe it.





At the top layer is your box for interfaceA, which has method1.





On the second layer you'll have two boxes - one for classA, another for classB. I think the "implements" arrow is a dashed line with a not-filled-in arrowhead. Also off to the side you'll have ClassC, with a normal line, no arrowhead, connecting it to ClassB (since classB has private ClassC a).





On the bottom layer you'll have classD with the "extends" arrow - which I think is a normal line with a filled in arrowhead, pointing to classB.





And when things are called like "vehicle" "car" "boat" "driver" and "sports car" it all makes a whole lot more sense than classA classB and classC :)


No comments:

Post a Comment