If you don't already know what the MVC pattern is, please read the [pattern.mvc] rule first.
It can be tempting for convenience to pass a View object (e.g. the HttpServletRequest) into a function that normally only deals with the Model, but this should be resisted. If there are repetitive tasks that relate to the Request or user session, manage them in helper classes, not in the Model.
Tip: HttpServletRequest shouldn't be seen outside the web related packages.
In the following example, a request is being passed in to a streaming service. A StreamingService is likely to be reused for applications other than the web, but by passing an HttpServletRequest into methods, the service is not as flexible as it could be.
public class StreamingService
{ private BillingServiceClient billingService; private VideoServiceClient videoService; public boolean acquireVideoAsset(HttpServletRequest request, String videoId) throws StreamingException { :
}
}
It would be better to extract anything required from the request into more generic objects that are not tied to a web application, such as a UserToken.
public class StreamingService
{ private BillingServiceClient billingService; private VideoServiceClient videoService; public boolean acquireVideoAsset(UserToken user, String videoId) throws StreamingException { :
}
}