In a large code base, what is a good practice between: Updating class properties inside the method vs. returning a value from the method and updating the property in the place where the call to the method was.
Example 1: Updating class properties inside the method
def sendFileToS3OrFileServer(Request request) {
if (settings.isS3())
request.s3Url = helper.uploadToS3(request.absoluteFilePath)
else if (settings.isFileServer())
request.fileServerUrl = helper.uploadToFileServer(request.absoluteFilePath)
}
//call the method above
sendFileToS3OrFileServer(request)
Example 2: Returning from the method instead of updating inside the method
String sendFileToS3OrFileServer(Request request) {
if (settings.isS3())
return helper.uploadToS3(request.absoluteFilePath)
else if (settings.isFileServer())
return helper.uploadToFileServer(request.absoluteFilePath)
}
//call the method above
request.commonS3OrFileServerUrl = sendFileToS3OrFileServer(request)
-
I would like to help but your question is a bit unclear, because I can't tell what the code is trying to accomplish; my advice is to either simplify your code into the essence of the problem (toy example), or give us enough context (class definitions, etc) so we can understand the full example.gardenhead– gardenhead2016年07月27日 01:43:17 +00:00Commented Jul 27, 2016 at 1:43
-
Yes more context please - specifically why is Request mutable, and the need for it to hold on to an S3 or a FileServerUrl? Are you trying to capture a Response to handle the action of uploading to S3 or a FileServer instead? As a side note, the uploadXXX() methods returning a url seems a bit awkward, as I would have expected the upload method to do one thing and one thing only - i.e. perform the upload function and maybe return a boolean indicating a success or a failure, not a url of where it uploaded to. It is unclear as to what you want to do with the url.srrm_lwn– srrm_lwn2016年07月27日 04:43:59 +00:00Commented Jul 27, 2016 at 4:43
lang-java