12

How could you explain the purpose of dependency injection to 5 years old child?

Comments
  • 2
    A toy needs batteries. therefore, you must 'inject' the battery into the toy.

    Something like that?
  • 0
  • 4
    Well ... you could tell them to make a mud pie.

    But to do that they have to go out dig up a pile of mud/clay *before* they can make it.

    Then you can tell them to make *another* mud pie, but this time you give them the mud to make it with.

    Wait ... are kids even allowed to play with mud any more?

    You might have to pick a different example ...
  • 0
    You give him a Lollipop, Not buy One himself. ;)
  • 3
    wait, why would a five-year old even need to know what DI is?
  • 3
    Probably referring to coworker.
  • 5
    Dave has a computer. It is very good and being a computer.

    Dave also has a printer, it is very good at printing pictures.

    Dave's computer knows how to say "print this image please", but it does not know how to print one itself because it is busy being a good computer. It depends on a printer for that.

    Dave's printer understands what "print this image please" means and how to do it because it is busy being a good printer.

    Disaster! One day, Dave's printer stops working :(

    Dave is worried, will he have to fix his computer or buy a new one? Of course not, because his computer doesn't know how to print, he doesn't have to!

    Because all printers understand "print this image please", Dave simply buys a new printer for his computer to depend on.

    "Hooray for separation of concern" says Dave.
  • 1
  • 0
  • 1
    @chrizzle the best explanation by far! 😀
  • 0
    The dependency injection is about dividing holding from accessing.
    You can say to 5 years old child that by watching video on YouTube it does not mean you have it on your laptop hard drive as file because by accessing video file from the internet it does not mean you actually download it.
Add Comment