|
-
Sep 2nd, 2005, 09:12 AM
#1
Thread Starter
Fanatic Member
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.
-
Sep 2nd, 2005, 11:43 AM
#2
Hyperactive Member
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
}
-
Sep 9th, 2005, 10:01 PM
#3
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|