All jobs / Backend developer / Architecture

Backend developer interview question · 0–1 years

Why would a class take its database client as a constructor parameter instead of creating one inside itself?

The strongest answer

The class stops deciding where the dependency comes from, so it can be given a different implementation — a test double, another configuration — and the wiring lives in one visible place instead of every constructor

Why it works

Right — testability is the visible benefit; the real one is that construction and configuration move to one place you can read.

What a good answer covers

Answers that fall short

Who gets asked this

More Architecture questions