2 ms·
The main advantage of IoC is to decrease coupling. The first code that you posted is highly coupled with FooValidator and FooFactory, every change to those obje
by tigershark 10y ago
The main advantage of IoC is to decrease coupling. The first code that you posted is highly coupled with FooValidator and FooFactory, every change to those objects (name, namespace, etc.) will have effects on your code.
Your code is also less flexible because is bound to exactly that validator and you have to explicitly change it in all the places where it is used if you want to use another one.
The better testability of the second code is just a nice side effect of IoC.
The fact that you cannot tell which type are your parameters is a ruby problem, certainly not an IoC shortcoming.