Decoupling Ruby: Delegation vs Dependency Injection

Time to read
less than
1 minute
Read so far

Decoupling Ruby: Delegation vs Dependency Injection

Tue, 18/02/2020 - 09:00
honeybadger

We've all worked with tightly-coupled code. If a butterfly flaps its wings in China, the unit tests break. Maintaining a system like this is...unpleasant. In this article, Jonathan Miles dives into the origins of tight-coupling. He demonstrates how you can use dependency injection (DI) to decouple code. Then he introduces a novel decoupling technique based on delegation that can be useful when DI is not an option. In Object-Oriented Programming, one object will often depend on another object in order to function.