Hi,
I have an LDAPUser Class.
It has 4 properties and One method as below.
public static LDAP FindLDAPUser(string emailaddress)
{
find user
if(user is found)
{
NewUser = new LDAP(sUID,sFirstName,sLastName,sEmailAddress);
return NewUser;
}
else
{
NewUser = new LDAP(empty values)
}
I am using the static method to contain my actual New contruct of the class.
In my code behind page of a webform(user enters an email address into a
textbox and presses enter).
I have the following code (drastically shortened):
private void cmdSearch_Click(object sender, System.EventArgs e)
{
LDAP NewUser;
NewUser = LDAP.FindLDAPUser(this.txtboxEmail.Text);
this.txtboxEmail.Text = NewUser.Email.ToString();
this.txtboxFName.Text = NewUser.FirstName.ToString();
this.txtboxLName.Text = NewUser.LastName.ToString();
this.txtboxUsername.Text = NewUser.EmployeeId.ToString();
}
Because my FindLDAPUser is a static method and actually creates the class
inside itself, is this bad OOD?
It works fine and everything, however because in the click event I do not
instantiate my class with new as below, my intellisence cannot pick up the
NewUser properties if I try to access these properties outside my if
statement. Please remember I left out a bunch of code.
LDAP NewUser = New LDAP(empty values);
I just don't like the idea of purposefully putting in bogus properties
values so that I can gain better access to my properties and methods. I would
then replace the empty values for the object with real values after I run the
FindLDAP user.
Should I just return a serialized peace of data from the FindLDAPUser method
and deserialize it into the new construct method?
I'd prefer not to instantiate an object at all if I can't find a user in the
first place after searching LDAP.
please advise.
thanks
chris