Related to Standard Naming Convention for DAO Methods and DAO class methods naming questions.
Why the methods in DAO classes are like:
getUserById(int id)
getUserByUsernameAndPassword(String username, String password)
instead of:
getUser(int id)
getUser(String username, String password)
in IDE like Eclipse auto-suggest will start to show you both when you start to type getUser. And according to the parameters you can choose which method is to go with.
Of course this is overloading. Why people avoid overloading and use different method names for different parameters? Or are they avoiding?
Regards.
Your proposed naming scheme fails in 2 (obvious) ways.
First way, conflicting method signatures:
getUser(int id);
getUser(int age);
getUser(String username, String password);
getUser(String firstname, String lastname);
Second way, unclear code requiring you to verify parameter types and names:
// What's being used to search for users in this code?
User user = getUser(poorlyNamedVariable);
Not to mention potential errors, when your variable isn't the type that you thought it was.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With