Question about UML and Java
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Omar_Komiha
Posted On:   Tuesday, July 16, 2002 05:49 AM

Hi, I have question concerning a Class Diagram in Java. Suppose you have you have the folowing elements: 1. Interface A 2. Class B (which implements A) 3. Class C In Class C an object "a" is created as follows: A a = new B(); How am I supposed to represent this in UML terms? should I draw a dependency between C and A or C and B? personally i think it will be the first one but of course I could be wrong. I'd really appreciate if some could help me with this. A second question imagine i create a second object, lets call it D. D implements    More>>

Hi,




I have question concerning a Class Diagram in Java.

Suppose you have you have the folowing elements:

1. Interface A

2. Class B (which implements A)

3. Class C



In Class C an object "a" is created as follows:

A a = new B();



How am I supposed to represent this in UML terms? should I

draw a dependency between C and A or C and B?

personally i think it will be the first one but of course

I could be wrong. I'd really appreciate if some could help

me with this.



A second question imagine i create a second object,
lets call it D. D implements A too.

Suppse now that i insert the following code in C:



new D();



should I add an dependancy between C and D or is the fact
that a dependancy between A en D already exists

make a dependancy between C and D unnecessary?



Thanks for your help!

   <<Less

Re: Question about UML and Java

Posted By:   Anonymous  
Posted On:   Friday, August 30, 2002 01:28 AM

Hi hopefully I can answer this.

The answer is that C depends on *both* A and B.

The answer to the second questions depends on what you do with the instance of D you've created. If you assign a data member of C to the new instance of D and that data member is of type D then it's an association. In all other cases it's a dependency.

Re: Question about UML and Java

Posted By:   Lance_Walton  
Posted On:   Tuesday, July 30, 2002 02:07 PM

Hi.

There is a (strangely) similar question in Sun's Java Forum. Please see http://forum.java.sun.com/thread.jsp?forum=31&thread=277849

Regards,

Lance

----

Lance Walton - lance@teaminabox.co.uk

Team In A Box - Software without Tragedy

http://www.teaminabox.co.uk

Re: Question about UML and Java

Posted By:   Christopher_Koenigsberg  
Posted On:   Tuesday, July 16, 2002 07:52 AM

Class diagrams are for static structure. This means type/structure declarations (package, static, class, members, "A myvara"). Local variables, runtime execution, dynamic assignment and instantiation of new class instances (e.g. "myvara = new B()"), are not part of static structure, so they play no role in a class diagram.



If you were doing a class diagram involving the static structure of class B, then of course you would show the association/generalization, that class B extends/implements/inherits from interface A.



If you were doing some dynamic modelling, in a Collaboration or State or Activity diagram, then it might be significant to the model, to show the involvement and behavior of an object of type B.

About | Sitemap | Contact