Definitions taken from here
Dependency
Change in structure or behaviour of a class affects the other related class, then there is a dependency b
The difference can be seen in the two constructors:
Dependency: The Address
object comes from outside, it's allocated somewhere else. This means that the Address
and Employee
objects exists separately, and only depend on each other.
Composition: Here you see that a new Engine
is created inside Car
. The Engine
object is part of the Car
. This means that a Car
is composed of an Engine
.