File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes association relation in class diagram Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "association relation in class diagram" Watch "association relation in class diagram" New topic
Author

association relation in class diagram

Ian Yang
Ranch Hand

Joined: Nov 27, 2001
Posts: 44
public class Class_A {
private Class_B b;
.....
// some methods
}
*****************************
public class Class_A {
private String abc;
public Class_B do() {
...
}
}
***************************
For the first code's case, should I draw A-->B
as the unidirectional association between A and B ? For the second code's code, I don't have Class_B type instance variable, but I have a method whose return type is Class_B, how should I draw the association between A and B ?
Thanks,
Ian
Wilfried LAURENT
Ranch Hand

Joined: Jul 13, 2001
Posts: 269
You can do the same thing while stereotyping your association with a returns tag.
#returns#
A --------------> B
PS: How to you deactivate the UBB Code? I wanted to type a stereotype with "less than" (x2) but it is interpreted
[ March 04, 2002: Message edited by: Wilfried LAURENT ]
Ian Yang
Ranch Hand

Joined: Nov 27, 2001
Posts: 44
Thanks. In the following class
public class Class_A {
public void doIt() {
Class_B b = new Class_B();
....
}
}
Since Class_B instance b is not Class_A's instance variable and no method in Class_A has a return type of Class_B, we should think there is no association relation between Class_A and Class_B assuming Class_B doesn't have any instance variable or method whose type is Class_A.
Is that right ?
Thanks,
Ian
Wilfried LAURENT
Ranch Hand

Joined: Jul 13, 2001
Posts: 269
It is not an association relationship but a dependency relationship. Which means on the diagram that it is not a straight but a dashed line.
#returns#
A - - - - - - - > B
mike zhang
Ranch Hand

Joined: Feb 26, 2002
Posts: 59
but as I learned, the dependency menas Class_B is passed as an argument of a method of Class_A, like
public class_A {
public void doIT(Class_B b) {
...
}
}
In this case, we draw A---->B meaning A depends on B, I don't think dependency applies to the case when Class_B is just created inside a method of Class_A.
can somebody verify it ?
Wilfried LAURENT
Ranch Hand

Joined: Jul 13, 2001
Posts: 269
You can used "Dependency" when a class uses another class but is not part of the class.
Dependency is a relationship which states that a change in one class may influence a change in another class. This statement applies for instance when B is a local variable of A.
If there is an API change in B, there may be some modifications in A.
That's what I learned
W.
Harpreet Hira
Ranch Hand

Joined: Sep 27, 2001
Posts: 72
Hi,
Dependency relationship can result in the following cases -
1. The instance B is passed to the method as the argument/parameter.
2. The instance B is created inside the the method.
3. Any other means by which the instance B is taken from some external resource, say, from a Factory class.
In all these 3 cases there is no association as the instance A doesnot directly know about the instance B, but still it depends on instance B, as any change in B would effect A.
Thus this is simple difference between association and dependency.
Any suggestions/corrections are welcome.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Does the concept of dependency contains the concept of association?
A class that contains an instance of another class, and calls its methods depends on the interface of the second.
Or we call a dependency only if it is not an association?


SCJP2. Please Indent your code using UBB Code
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
This is a response that I made on a very similar question that was asked on this same subject.
The UML includes a general dependencyrelationship, which indicates that one element (of any kind, including classes, use cases, and so on) has knowledge of another element. It is illustrated with a dashed arrow line. In class diagrams the dependency relationship is useful to depict non-attribute visibility between classes, in other words parameter, global, or locally declared visibility. By contrast, plain attribute visibility is shown with a regular association line and a navigability(Larman).
Hope this helps.
Craig
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: association relation in class diagram