Populating data in classes

N

Nemisis

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"??
Cheers
 
N

Nemisis

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?
 
N

Nemisis

tdavisjr said:
Yes. This is a better option. Other than that, you look fine.

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top