News for hackers. Stuff that matters.
Re:Ask HN: Concepts that clicked only years after you first ... by azeemba on Sunday January 01, 2023 @10:18AM (#34206928)
Let's say Class A depends on Class B. A lot of people have the instincts to have A construct B so that the callers of A don't have to worry about it.

But this makes testing A in isolation difficult. When testing A, you want to mock out B with an instance the test can manipulate.

So we want A to not create B, instead we want B to be "injected" into A. The general strategy of having B passed into A is called dependcy injection.

There are no comments on this comment yet.