Results 1 to 3 of 3

Thread: OO Design Question

  1. #1

    Thread Starter
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681

    OO Design Question

    Design question:

    Say I have a universal database that holds person data - ie. First name, last name, all things that a person MUST have. Then I have a second database that has a table that holds person data specific for the particular business like compliance score, training level, etc. What would be the correct way to represent this using OO in .NET?

    Options:
    1) Create an object SpecificPerson and have a GenericPerson object within it – so that the GenericPerson can handle the saving of its own data into the universal database table while the SpecificPerson can save its own data in the specific table. However this would require notation like SpecificPerson.GenericPerson.FirstName and this does not make use of inheritance.
    2) Have SpecificPerson inherit from GenericPerson. But then GenericPerson would not be handling it’s own data retrieval and updates, and I would have to maintain 2 different dirty properties, valid properties, userstamps, change timestamps, etc. and write logic to react appropriately.

    Any input is greatly appreciated.

  2. #2
    Hyperactive Member GlenW's Avatar
    Join Date
    Nov 2001
    Location
    Gateshead, England
    Posts
    479

    Re: OO Design Question

    I prefer No 2.
    Have the base class save its data and any inheriting classes save their own.
    So in an inheriting class you would have:

    private override void Save()
    {
    base.Save();
    // My save bits
    }

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: OO Design Question

    Option 1 is a "HAS A" type relationship and option 2 is an "IS A" type relationship. Just ask yourself which of these statements sounds more correct:

    1. A SpecificPerson HAS A GenericPerson
    2. A SpecificPerson IS A GenericPerson

    I think the answer is pretty clear. You just need to find as clean a method as possible of overcoming the issues that arise. The SpecificPerson can have method that override the equivalent methods in the GenericPerson, which would perform the required data access for the SpecificPerson and then call the base methods to handle data access for the GenericPerson. You could use Private members in the base class so that the derived class does not need to remember certain things that relate only to the base class.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width