UML class diagram – can aggregated object be part of two aggregated classes

classclass-diagramuml

Some sources say that aggregation means that the class owns the object and shares reference. Lets assume an example where a company class holds a list of cars but departments of that company has list of cars used by them.

class Department
{
   list<Car> listOfCars;
}

class Company
{
   list<Car> listOfCars;
   //initialization of the list
}

So in UML class diagram, I would do it like this. But I assume this is not allowed because it would imply that both company and department own the objects..

[COMPANY]<>------[CAR]
[DEPARTMENT]<>---|        //imagine this goes up to the car class

Best Answer

Mind the difference between aggregation and composition!

While in an aggregation instances of both associated classes may exist without a relation (e.g. a restaurant and a chair), for a composition the one can not exist without the other (e.g. a child without a parent).

In your case an aggregation seems more appropriate to me, and than it is no problem to model a aggregation between Department and Car AND Company and Car.

Besides that: such a situation is often modeled like Company <*>-- Department <>-- Car (where only Department stores the list of cars).