views:

139

answers:

3

Hi there,

been creating a few wcf methods and i have a mehtod called IsValidLogin ... there various versions, 1 takes 2 strings, 1 takes an object etc.

Of course in WCF you can't overload methods can anyone suggest the best way to name these methods..

I was thinking of IsValidLogin1, IsValidLogin2??

But i am open to any suggestions

Thanks in advance

A: 

I don't think that IsValidLogin1,2, etc. is clear enough. When you overload methods normally, you don't have to worry about names because it's the same name with different parameters, however in this case you have to remember the parameters for each method, and numbers could get confusting.

I might suggest IsValidLoginNumStr etc, which is to say, maybe list key parameters in the method name to help remind you which method you're referring to. Either that or if one takes a password, then IsValidLoginPass, or something of the like. I say this because I'm a fan of long, descriptive method names. If you want to keep the name short as possible, and you can think of a letter that would help, like P for password, or O for object, then tack on a helpful letter at the end. Something more than a number will help you in the long run

Elaina R
+3  A: 

When you start adding index numbers to your identifiers, you're usually doing it wrong.

One way I've seen is adding "With" and the parameter names to the name, i.e. IsValidLoginWithUsernamePassword, and IsValidLoginWithToken (assuming your object is some kind of authentication token). These are kind of long though.

I'd just call the methods IsValidUsernamePassword and IsValidToken.

Matti Virkkunen
Thanks a lot, this was just what i needed.
mark smith
I usually use "By", but same concept.
GalacticCowboy
@GalacticCowboy: I prefer "By" for methods that are mainly used to fetch data. `GetUserById` and whatnot.
Matti Virkkunen
A: 

First of all, you should stick with message/contract first methodology when working with wcf services, passing in a request and returning a response. This will save you a lot of headache down the road.

That being said, you should create two methods like so:

public LoginValidResponse IsLoginValid(UserObjectRequest userRequest)

and

public LoginValidResponse IsLoginValid(UsernamePasswordRequest usernameRequest)

There are probably better names for these, but you get the idea. If you provided more information about what you were passing in and back, I could help out with naming a bit more.

Notice these two methods return the same response LoginValidResponse.

Put your two strings in the UsernamePasswordRequest (I'm assuming the strings are username and password). Put the User Object in the UserObjectRequest.

You can also reuse these requests / responses in later methods, e.g, GetUserInfo(UserObjectRequest request).

The LoginValidResponse will contain your bool (and any other information you want to pass back in your response).

*Note - I only named the methods IsLoginValid b/c that was your question. On top of the request / response pattern, I might also rename the methods to something like ValidateLoginByUser and ValidateLoginByUsername (or something like that).

CkH