Introduction
Dependency Inversion is a well-known software development principle, described by Robert C. Martin as the responsible of sy...
For further actions, you may consider blocking this person and/or reporting abuse
Hey man, great article!! I always try to implement this pattern on my code. One thing that a make different, is that I use defdelegate on the port, I think that make the code more easy to understand. But thanks for the excellent article
Doesn't assigning it to
@adapter
make it a compiled variable, breaking theApplication.put_env
trick?Yes @03juan, didn't notice that
I think you're right, in this case we need to move to a private function instead
defp adapter, do: Application.get_env(:my_system, __MODULE__)
Doesn't it?
Yep! You right! I already change this implementation, and now I use Application.get_env instead
Great tip, Bruno! Thanks for the feedback
Hi Bruno,
I don't quite understand why the delegate or function call of the behavior should be made in the port, what's the porpuse?
It's because all the application use the
MySystem.SmsNotificationPort.notify/2
function?Hey Diego!! How are you?
Well, I use the delegate on the port, because the port's idea is to be an interface. The only responsibility of the port is to call the correct adapter.
Awesome content!
Paring this with mox for testing makes testing so much simpler
Yep! I like to use with Hammox! It's a really good abstraction for the mox