I have to work with some code that isn't truly MVC (i.e., it doesn't use an explicit framework among other things). Right now we make do with servlets that pass data to services.
Here is my problem. I am receiving a post to a servlet that contains a whole bunch of address data that I have to save to the database. The data is (obviously) in the HttpServletRequest
object. My question is, how do I pass this data into a service? I am reluctant to do it like this:
AddressService.saveAddress(request);
Because I don't think the service should have a dependency on the request. My other option is to do something like this:
String addressLine = request.getParameter("addressLine");
..
.. about 7 other parameters
..
String zip = request.getParameter("zip");
AddressService.saveAddress(addressLine, ... 7 other parameters ..., zip);
But I don't like having a function with a huge number of parameters either. I was thinking of making an intermediate object called AddressData
that would hold data from the request, and then passing that into the service. Is that an acceptable way of doing things?