I'm reading Laravel's documenation and got a bit confused at Facades section.
In the very first paragraph of "Facades vs DI" subsection it's said: "One of the primary benefits of dependency injection is the ability to swap implementations of the injected class."
How come injected class's implementaion be swaped??
My suggestion that it's Dependency Inversion princicple, which says that high level classes should not depend on low level classes.
Say we're injecting Mailer class. In dev and prod modes we want this class to be implemented differently, in one case it should use Mailgun and in another custom written code. So we make appropriate bindings devending on the env in the Service Provider. As the result we swapped implementaion of Mailer class in 2 different modes.
Here's snippet:
public function __construct(Mailer $mailer)
{
$this->mailer= $mailer;
}
Am I thinking in the right way??
via Sanzhar Dan