1

I have a scenario where I'm using an external service which requires a big hash of parameters like so:

def external_service_params(user, invoice)
  {
    name: user.name,
    email: user.email,
    phone: user.phone,
    invoice_id: invoice.id,
    invoice_number: invoice.number,
    invoice_total: invoice.total
  }
end

Is this a case of either "feature envy" or "data envy"? If so, the solution is to move the method into the other object. But I feel uncomfortable with this because the set of data that is required only concerns the external service. If I kept doing that I feel like my other data objects would be bloated with many methods. Am I misinterpreting the smell or are there better solutions?

  • 1
    consider introducing an [anti-corruption layer](http://programmers.stackexchange.com/a/184472/31260) – gnat Jul 03 '15 at 05:45
  • Thanks for the link. Could my `external_service_params` method then be an example of a method on the anti-corruption layer? – Mark Agbuya Jul 03 '15 at 05:57
  • from your description of the problem it sounds like it – gnat Jul 03 '15 at 06:15

0 Answers0