Search code examples
python-3.xooparchitecture

The difference between accepting multiple parameters and accepting a single object


I write a library that deals with an API and I am considering two interface options:

1. api_client.init_payment(order_id=..., price=..., ...)

2. api_client.init_payment(InitPaymentRequest(order_id=..., price=..., ...))

Generally, I don't see a big difference between them. I only prefer the [1] since it is more minimalistic and easy to use. But I'll have to create the InitPaymentRequest object internally anyway, so I just was thinking maybe [2] also makes sense... But is it justified?

Which option is generally better?


Solution

  • I decided it is inconvenient for clients when they are forced to create a request object. Especially when an API method accepts only one parameter. So I think the [1] is better. The only drawback is that I still have to create a request object under the hood and if a new API parameter gets introduced, I'll have to add it in two places (the APIClient method and the Request class). But it is not a big deal.