There is a struct/class called User
. It has many properties like firstName
, lastName
, address
, phoneNumber
, creditCardNumber
, etc.
I need to design a function which validates the a particular user's credit card number. The function can be designed in two ways.
First Method
bool validateCreditCard(userCardNumber string, inputCardNumber string) {
return userCardNumber == inputCardNumber
}
Second Method
bool validateCreditCard(user User, inputCardNumber string) {
return user.creditCardNumber == inputCardNumber
}
Out of these two methods, I feel the first method is more precise in its signature and what it does. The second method takes the User
as argument and uses only the creditCardNumber
field. Second method gets data which it does not depend on. Is this an anti-pattern? If yes, can I get more links on this?
Aucun commentaire:
Enregistrer un commentaire