Search code examples
visual-studio-2010classumlclass-diagram

Does a method count as an association?


Taking into consideration this class diagram:

There is a "has a" (aggregation) between the two, if I'm not mistaken, because Library actually can hold a handle to an instance of a book. enter image description here

Now, what about this diagram?

enter image description here

Is there an association between the two? LibraryService never stores an instance of Book in it, but one of it's method returns an array of books. What relationship would there be between the two classes?

On a related note, Visual studio does not seem to allow you to link methods to objects when it generates a class diagram. This is what led me to ask this question.


Solution

  • Is there an association between the two? LibraryService never stores an instance of Book in it

    Then the answer is no. A relationship represents some kind of cooperation between the two classes, e.g. by exchanging messages or querying a status (Seemann 2006, p. 53, "UML2"). In this case, the two do not cooperate. Probably, your LibraryService only serves the Library which then has a connection to "book".

    but one of it's method returns an array of books.

    You convey that information already in the method list - which is fine :)

    If you wanted a relationship you'd have to be able to add semantics to it which in this case would just be redundant but less understandable.