Friday, March 16, 2012

Populating data in classes

Hi all,

I have 2 classes, for example. I have a Company class and a contact
class.

each class has the following properties

Company
ID
Name
Town
Ref

Contact
CompanyID
FirstName
LastName
Email

Now if i am retrieving the data from my database and filling the
contact class, is it ok to populate the contacts companyname, for
example

Contact.FirstName = "XXX"
Contact.lastname = "XXX"
Contact.Company.ID = 99
Contact.Company.Name = "XXXX"

Is this best practice, or should i be doing this another way? I
thought this would make sense to do, as most of the time if i have a
contact class, i usually want to show the companyName.

Anyone know of a better way to do this, or the "best practice way"??
CheersOr maybe it would be better to write another New constructor that
accepts the ID and Name?

Contact.firstname = "ZZZ"
Contact.Lastname = "CCC"

Contact.Company = New Company(99, "CCCCC")

Is this a better option?
Yes. This is a better option. Other than that, you look fine.

"Nemisis" <darrens2005@.hotmail.comwrote in message
news:1158670936.010052.6720@.d34g2000cwd.googlegrou ps.com...

Quote:

Originally Posted by

Or maybe it would be better to write another New constructor that
accepts the ID and Name?
>
Contact.firstname = "ZZZ"
Contact.Lastname = "CCC"
>
Contact.Company = New Company(99, "CCCCC")
>
Is this a better option?
>


tdavisjr wrote:

Quote:

Originally Posted by

Yes. This is a better option. Other than that, you look fine.
>

Quote:

Originally Posted by


Contact.firstname = "ZZZ"
Contact.Lastname = "CCC"

Contact.Company = New Company(99, "CCCCC")

Is this a better option?


Tdavis,

Thanks for the reply, i do agree with you, because it looks neater, but
do you have any other reason why you think this is better?

0 comments:

Post a Comment