Dependency injection

The Dependency injection (DI) pattern  is the first of many design patterns in this book that were not described in the Gang of Four book. There's a good reason for that. The DI pattern has sprung from the unit-testing movement, and in 1994, unit testing was not yet a thing. In that era, applications were treated as monolithic blocks of code, and not as collections of loosely connected units.

DI works by changing responsibility for object creation. In classical OOP, each object creates new objects that it needs for functioning. This makes the program very rigid and hard to test. DI turns this on its head. If an object needs other objects to functions, the owner (the code which creates the first objects) should also create ...

Get Mastering Delphi Programming: A Complete Reference Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.