The difference can be seen in the two constructors:
-
Dependency: The
Addressobject comes from outside, it’s allocated somewhere else. This means that theAddressandEmployeeobjects exists separately, and only depend on each other. -
Composition: Here you see that a new
Engineis created insideCar. TheEngineobject is part of theCar. This means that aCaris composed of anEngine.