we are looking for the best practice to develop business clases in Scala, problems:
1.- With exceptions: The code that usa a method that throws an exception is not aware that have to handle the exception or if the exception is not handled immediately It have to be handled in an upper layer for example to show an special error. Suppose a Login library, you send "user" and "password", the library returns a LoggedUser with all information about user, but if the user does not exist the library throw BadPasswordExeption or UserNotFoundException. At the end if I use that library I dont know what exceptions are thrown by the library. I can inspect the source to investigate but It is not the point.
2.- Either and Try: The problem with this is that you have to test the result of every invocation method. For example whit the login method you have to test it, if it was successful do other action but if it fails... it fails for?, and how you can propagate the error to handle it in the upper layer to answer with the right response (may be an http code or a error message). The worse case, a business method invokes three methods that returns Try[Result], so you have to test the result of the first to execute the second and then execute the third.
Aucun commentaire:
Enregistrer un commentaire