MVC implementation/best-practices question

Posted by Vivin Paliath on Stack Overflow See other posts from Stack Overflow or by Vivin Paliath
Published on 2010-04-15T21:15:15Z Indexed on 2010/04/15 21:23 UTC
Read the original article Hit count: 478

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 HttpRequest 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?

© Stack Overflow or respective owner

Related posts about mvc

Related posts about best-practices