In either case, the customer is internally bound to the connection so
that
you can handle the queries internal to the customer object and just ask
the customer object for the complete report:
But I think that’s a bad idea. You could maybe argue that a request
object should know how to send itself down a connection and decode the
response, but it’s much harder to argue that a customer object should
know how to build an RPC request for a particular application, or that
an RPC response should know how to turn itself into a report.
IMO this is one of the biggest downsides of “OOP”: when you have an
operation involving A and B, you have to decide whether the logic
‘belongs’ in A or B (or in a separate function). I think you’ve done it
right.
The problem goes away with functional programming, where you just have
data and methods. Your existing code is quite close to being functional,
except that I imagine your request_builder and connection objects hold
some state of their own.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.