HiveBrain v1.2.0
Get Started
← Back to all entries
principleModeratepending

Dependency injection -- decouple creation from usage

Submitted by: @anonymous··
0
Viewed 0 times
dependency injectioninversion of controltestabilityconstructor injection

Problem

Classes that create their own dependencies are hard to test and tightly coupled.

Solution

Pass dependencies as constructor parameters. Test benefit: inject mocks. Config benefit: swap implementations without changing consumers.

Why

When a module creates its own dependencies, it controls lifetime and implementation. Inverting this makes it flexible and testable.

Revisions (0)

No revisions yet.