What is a good metaphor for dependency injection?

The metaphor that stuck with me when programming systems other than DI is "a man playing with his toys." The person who is the object and the face of the toy, which is something that the object creates, stores, initializes and manipulates. Toys can send events when they reach a certain state, but they do not know anything about the person using them; these are just small black boxes with control switches that make up their interfaces. A person can listen to events from toys and react by manipulating their interfaces. A person can do whatever he wants with his toys, but he probably should not interfere with his insides, because they can break.

The chaos that DI inflicts on my metaphor is that it turns toys into conscious beings that know their owner, the person who uses them. Toys can manipulate this person, but the person knows nothing about how they work and do not even care. The person simply owns the toys and expects the toys to manipulate him / her on their own satisfaction with the toys.

WTF ?? That sounds awful !!
What is a good mental metaphor they used to think about how DI systems work?

+5
source share
8 answers

Good sources are a good example for SOLID motivational images .

metaphor of the dependency injection principle

+3

, . ( DI) ( ), ( , , , "":-)); ( ) , , ( ).

, , - , DI - , - . , , , .

+10

, DI DI DI, - , , , . DI , . , , , , , .

+2

Legos.

Lego , ( ) ( ).

Legos, (). . ( ), () / (). . , , ( main() Spring ..).

... , Legos , : -)

+2

. , (DI) , . , DVI, , . , USB-, , .

- DI.
- .
// - , DI () .

+2

. , , , , , - .

+1

DI, , CD-. , CD ; CD, , , , .

+1

. ninject: http://ninject.org/. " Dojo" . , , , .

0

All Articles