3 ms·
> There's a line where it gets absurd as it makes the code more complex. There's no good reason to be adding a date variable to your method signature just to ma
by laureny 14y ago
> There's a line where it gets absurd as it makes the code more complex. There's no good reason to be adding a date variable to your method signature just to make everything functional. Because you then have to declare and initialize that variable extra times.
Exactly, and that's why DI is useful: it forces you to make a distinction between dependencies and real parameters. You really want your method signature to only accept parameters that are going to change throughout the life of your application while being injected with the dependencies it needs. Something like:
@Inject
private Database db;
public void updateName(String id, String name) {
User u = db.find(id);
u.setName(name);
db.save(u);
}
Your logic is now clearly separated from the dependencies and trivial to test.