• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

association relation in class diagram

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic