Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dependency injection and aggregation/association

In both association and aggregation, one class maintains a reference to another class.

Then, does constructor injection imply composition? Going by the same logic, is it safe to say that setter injection leads to an association, and not an aggregation?

like image 412
Abhijeet Kashnia Avatar asked Mar 14 '26 13:03

Abhijeet Kashnia


1 Answers

An aggregation is merely another representation of an association. So setter injection leads to an association and aggregation -- as does constructor injection.

It's debatable as to whether constructor injection implies composition since, according to a strict interpretation of composition, the class itself must be responsible for both the construction and destruction of the composite class.

like image 105
Randolpho Avatar answered Mar 16 '26 09:03

Randolpho



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!