wood burning stoves 2.0*
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Dependency Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Dependency Doubt" Watch "Dependency Doubt" New topic
Author

Dependency Doubt

Chaminda Amarasinghe
Ranch Hand

Joined: May 17, 2006
Posts: 402
I have a doubt about "Dependency" relationship.

lets take this example

class A {
void methodA (B b) {
C c = new C() {
}
}

What are the Dependencies of Class A?
Both B and C or
Only B

Can someone plss explain

Thanks
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
B and C.

It's easy to identify dependencies, just take a look at import section, dependencies within the same package are not display anyway.
[ December 22, 2008: Message edited by: Kengkaj Sathianpantarit ]

SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
Chaminda Amarasinghe
Ranch Hand

Joined: May 17, 2006
Posts: 402
Thanks Kengkaj,

Actually my answer is also B and C. But today I generated some class diagrams (Reverse Engineering) using netbeans uml module for existing classes. But in those diagrams no any C type dependency has been shown. Only B type dependencies. Also I can remember (not sure) Mark Cate book explains some where the dependency as If some class uses other class as an argument or a return type of a method. Both these cases made this doubt to me.

Lets check others view

Thanks again for the reply
[ December 22, 2008: Message edited by: Chaminda Amarasinghe ]
Scott Soo
Ranch Hand

Joined: Oct 02, 2008
Posts: 83
Originally posted by Chaminda Amarasinghe:
Thanks Kengkaj,

Actually my answer is also B and C. But today I generated some class diagrams (Reverse Engineering) using netbeans uml module for existing classes. But in those diagrams no any C type dependency has been shown. Only B type dependencies. Also I can remember (not sure) Mark Cate book explains some where the dependency as If some class uses other class as an argument or a return type of a method. Both these cases made this doubt to me.

Lets check others view

Thanks again for the reply

[ December 22, 2008: Message edited by: Chaminda Amarasinghe ]



Hi,

Based on the code, A depends on B but references (associates) with C. Hence dotted line for B but solid line for C. Dependency is because the method behaves depending on the state of B which A manages the state of C as A is referencing.

Above is my opinion. Hope is helpful.

Cheers!!
Scott Soo
Ranch Hand

Joined: Oct 02, 2008
Posts: 83
Originally posted by Scott Soo:



Hi,

Based on the code, A depends on B but references (associates) with C. Hence dotted line for B but solid line for C. Dependency is because the method behaves depending on the state of B which A manages the state of C as A is referencing.

Above is my opinion. Hope is helpful.

Cheers!!


Oh. My apology. Just realised that C is internal to the method. Hence, the solid line may not be shown since C is not a member of A.

Thank you.
Scott Soo
Ranch Hand

Joined: Oct 02, 2008
Posts: 83
Oh. One more thing to add. Since Class diagram only mostly show the operations and members of a class and corresponding relatiohsips, internal implementation is not shown. Class C is an internal implementation of an operation and, hence, the tool did not generate the relationship.

Do share your thoughts.

Thank you.

Cheers!
Chaminda Amarasinghe
Ranch Hand

Joined: May 17, 2006
Posts: 402
Thanks Scott,

If I understood you correctly, Theoretically A depends on both B and C but generally since class diagrams do not show internal implementation the dependency to C is not shown.

Regards
Scott Soo
Ranch Hand

Joined: Oct 02, 2008
Posts: 83
Originally posted by Chaminda Amarasinghe:
Thanks Scott,

If I understood you correctly, Theoretically A depends on both B and C but generally since class diagrams do not show internal implementation the dependency to C is not shown.

Regards


Hi,

It may not sound correct. I will say A is only dependent on B from the UML class diagram and design perspective and there is no dependency on C. My reason is that there seems to be a "dependency" C because of the way the operation is implemented. When a developer see the class diagram, he or she does not see C at all. When he or she implements it, he or she introduces C. This may not happen for another developer who may implement differently without C when receive the same class diagram. This issue or misunderstanding is only caused when doing reverse engineering to generate the class diagram.

Hope the above clarify your doubts.

Cheers!
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Originally posted by Chaminda Amarasinghe:
Thanks Kengkaj,
Actually my answer is also B and C. But today I generated some class diagrams (Reverse Engineering) using netbeans uml module for existing classes. But in those diagrams no any C type dependency has been shown.

Don't care representation in diagram much, you might be misled.

Dependency in general term, not UML term, means if A depends on B, if B has changed it might affect A.

For example if we use reflection API, to load class B or C dynamically by using Class.forName method, does dependencies gone for good?

No, it still be there, changing B or C still able to affect A, but we cannot see these in UML diagrams.
[ December 22, 2008: Message edited by: Kengkaj Sathianpantarit ]
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Originally posted by Chaminda Amarasinghe:

Theoretically A depends on both B and C

Not theoretically, it really depends.
Chaminda Amarasinghe
Ranch Hand

Joined: May 17, 2006
Posts: 402
Kengkaj, Scott, Thank you very much.

Actually I reffed term "dependency" in UML world. So I think in that case Scott's explanation is correct. But in case of class loading scenario, A depends on both B and C.
 
 
subject: Dependency Doubt
 
Similar Threads
doubt in || and &&
Coupling doubt.
Doubt with ==
Doubt
IS - A doubt