Populating data in classes

Discussion in 'ASP .Net' started by Nemisis, Sep 19, 2006.

  1. Nemisis

    Nemisis Guest

    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
    Nemisis, Sep 19, 2006
    #1
    1. Advertising

  2. Nemisis

    Nemisis Guest

    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?
    Nemisis, Sep 19, 2006
    #2
    1. Advertising

  3. Nemisis

    tdavisjr Guest

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

    "Nemisis" <> wrote in message
    news:...
    > 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, Sep 19, 2006
    #3
  4. Nemisis

    Nemisis Guest

    tdavisjr wrote:
    > Yes. This is a better option. Other than that, you look fine.
    >
    > >
    > > 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?
    Nemisis, Sep 19, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John
    Replies:
    1
    Views:
    375
  2. Machelle Chandler
    Replies:
    1
    Views:
    1,964
    Thiago Almeida
    Oct 16, 2003
  3. luna
    Replies:
    3
    Views:
    406
    Mark Fitzpatrick
    Jan 27, 2004
  4. =?Utf-8?B?Z2c3Nw==?=
    Replies:
    3
    Views:
    698
    Eliyahu Goldin
    Aug 18, 2005
  5. Trevoke
    Replies:
    10
    Views:
    193
    Brian Candler
    Jul 22, 2009
Loading...

Share This Page