The difference can be seen in the two constructors:
-
Dependency: The
Address
object comes from outside, it’s allocated somewhere else. This means that theAddress
andEmployee
objects exists separately, and only depend on each other. -
Composition: Here you see that a new
Engine
is created insideCar
. TheEngine
object is part of theCar
. This means that aCar
is composed of anEngine
.