DEV Community

Discussion on: Design choice

Collapse
 
rahulbarwal profile image
Rahul Barwal

payer.transfer(payee, amount);

  • We are sure that payer exists.
  • Better for situations with individuals and their transactions.

transfer(payer, payee, amount);

  • Needs checks to be sure whether the payer is there or not.
  • Better when we have a large no of payers(may be in an array).
  • In bigger repositories it comes in handy, when you have defaults in place for payer. Obviously this does not make much sense for this particular example. But I've faced some situations where if the argument comes then behaviour is something else we have to switch to default.

As you can see there are pros and cons to both, personally I would prefer second approach as it gives us the flexibility to have defaults.
Most of the library developers tend to provide both the approaches.