• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question regarding association

 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a class with a method which returns, let's say, an object of type X - should I use an association to class X? I think that I should not because associations should be used when we have an instance variable of the particular type. Please, clear my confusion.

The second question. I have a class with an instance reference to class java.util.Random (I use only nextDouble() method, but many times). I think that I should mark it as an association to class Random and I am going to write nextDouble() in the class rectangle only. Am I correct?

Thanks a lot my friends!
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If object x comes from object y, then there is an association between the objects. In order to clearly describe this relationship in a Class diagram, you may use the symbol for Association. Note that in the UML, there are other types of relationships, e.g. Composition, Aggregation, etc.

In terms of the second question, you can certainly specify the method being used in a Class diagram, e.g. nextDouble(). This would be understandable. Moreover, in some Class diagrams you may chose not to include any methods and simply use the names of the Classes. In other Class diagrams, you might only specify the fields and not include the methods. It depends on the situtation and how "you" want to use the diagrams, who will read the diagrams, and other factors.
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks James.

In the first case the object is instantiated inside the instance method and then - returned. So I should mark it as a kind of association?
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you may want to mark it as an Association since there is a relationship between the objects.
 
Vlad Varnica
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't know the trick I use is to reverse engineer my code inside an UML tool and see if my association is detected.
If not detected then maybe association should be written at attribut level while mapping annotations are certainly at method level
I found this image on the web: http://www.forum-omondo.com/documentation_eclipseuml_2008/Eclipse_Database/Create_associations/one_to_many_mapping.png
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic