davidinho
davidinho

Reputation: 169

aggregation involves dependency?

I'm doing an UML diagrams for a project but I have a doubt... I use an example to explain:

public class Book{...}

public class Library{
    private ArrayList<Book> books;

    public void insert(Book b){...}

    public Book get(Book b){...}
    }

In this case between Book and Library there's an aggregation but also a dependency, right? Aggregation is a relation in which the "parent" class contains the "child" class, instead the dependency is the case in which a class use another class by parameter or return type. Now, if a class A contains object of another class B mean that the B's object has been passed in some way at the object of class A, the only way is using a method(or a constructor), so the aggregation involves the dependency?

P.S.: sorry for my poor english

Upvotes: 2

Views: 389

Answers (2)

vainolo
vainolo

Reputation: 6987

With all due respect to your professor, I disagree. You do have aggregation in your diagram, since Library contains Books (both semantically and syntactically).

A UML dependency relation means that "some UML element or a set of elements requires, needs or depends on other model elements for specification or implementation" (from my favorite UML reference site: uml-diagrams.org). When you put an aggregation link between two elements, it is already stated that one depends on the other, therefore adding a dependency relation between them is redundant.

Upvotes: 4

emesx
emesx

Reputation: 12755

I am no UML expert, but one thing I've really liked in "UML in a Nutshell" was a sentence saying that UML is useful only when it's intuitive for everybody.

Having said that, I'd suggest not over-complicating your diagrams. Not everything can nor has to be presented in a diagram. In your case the Library has some Books, a case of aggregation/composition (depending on other details not mentioned in your description). You dont have to state a dependency between these two classes, because the aggregation implies it. In my understanding a "dependency" is useful when you want to state an indirect relationship, a runtime dependency for instance.

Upvotes: 1

Related Questions