nanovche / expense-tracker

Rest api with spring boot; follows youtube tutorial
0 stars 0 forks source link

pass the whole `User` object as a paramaeter instead of its properties #14

Open velizartodorov opened 3 years ago

velizartodorov commented 3 years ago

https://github.com/nanovche/expense-tracker/blob/62d3f2e5dc3c7f51fe5f968d5518da08cef777ae/expense-tracker-api/src/main/java/com/pairlearning/expensetracker/repository/UserRepositoryImpl.java#L39

nanovche commented 3 years ago

What do we gain be passing the whole obj?

velizartodorov commented 3 years ago

Simplicity of the function. In a perfect case, a function would have 0 parameters and will do it's job out of the box. Very often that's not the case. Bob Martin suggests, that a function with more than 3 parameters is suspiciously bad designed. In this case it's hard to notice, as the User object is quite simple, but imagine the following scenario: public Integer create(String firstName, String lastName, String nickName, String phone, String skypeNickName, String email, String password, Boolean gender, Date birthDate, String hobby, String eyeColor) throws EtAuthException {

It will be hell for the users of your function (no matter if it's API or your colleges, or you yourself in an year) to call it. This can be simplified to: public Integer create(User user) throws EtAuthException {