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 question regarding association 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 "question regarding association" Watch "question regarding association" New topic
Author

question regarding association

Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

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!


SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
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

Joined: Apr 20, 2009
Posts: 804
    
    1

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

Joined: Apr 16, 2008
Posts: 2187
Yes, you may want to mark it as an Association since there is a relationship between the objects.
Vlad Varnica
Ranch Hand

Joined: Dec 28, 2002
Posts: 40
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question regarding association
 
Similar Threads
Class Diagram -Association & Inheritance
Is that an association?
Dependency vs. association ?
Association or Not
Hibernate Association