Home > Archive > ASP .NET > October 2006 > OOP relationships. Advice needed!! PLEASE
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
OOP relationships. Advice needed!! PLEASE
|
|
| Nemisis 2006-10-31, 7:06 pm |
| Hi all,
I am trying to work out whether my objects whould contain child objects
or just an ID property to the linking object.
I have the following table in my SQL database
tblCompany
ID
Name
SalespersonID
Then a have tblSalesPerson
tblSalesPerson
ID
FirstName
LastName
If i am going to design this, is it best OOP practice to include the
SalesPersonID within the Company object, or would i create a
CompanySalesperson object within the company object.
If anyone has a good article to read on this, or can explain it too me,
i would really really really appreicate it. Ta
| |
| Eliyahu Goldin 2006-10-31, 7:06 pm |
| What is your model? A SalesPerson is an employee of a Company and there can
be multiple SalesPersons within one Company? Or A SalesPerson sells to a
Company and there can be multiple Companies for one SalesPerson?
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Nemisis" <darrens2005@hotmail.com> wrote in message
news:1162307477.855340.36640@e64g2000cwd.googlegroups.com...
> Hi all,
>
> I am trying to work out whether my objects whould contain child objects
> or just an ID property to the linking object.
>
> I have the following table in my SQL database
>
> tblCompany
> ID
> Name
> SalespersonID
>
> Then a have tblSalesPerson
>
> tblSalesPerson
> ID
> FirstName
> LastName
>
> If i am going to design this, is it best OOP practice to include the
> SalesPersonID within the Company object, or would i create a
> CompanySalesperson object within the company object.
>
> If anyone has a good article to read on this, or can explain it too me,
> i would really really really appreicate it. Ta
>
| |
| Chris Fulstow 2006-10-31, 7:06 pm |
| First, I'd change the design of the database because currently each
company can only have one salesperson. Remove the SalespersonID field
from the Companies table and add a CompanyID to the Salespeople table.
Then you can have more then one salesperson with the same CompanyID,
which is a one-to-many relationship between Companies and Salespeople.
You could then implement this in your .NET code as having a Company
object which holds a reference to a list of SalesPerson objects, for
example:
List<SalesPerson> salespeople;
This type of relationship between Companies and Salespeople is called
"composition".
--
Chris Fulstow
MCP, MCTS
http://chrisfulstow.blogspot.com/
Nemisis wrote:
> Hi all,
>
> I am trying to work out whether my objects whould contain child objects
> or just an ID property to the linking object.
>
> I have the following table in my SQL database
>
> tblCompany
> ID
> Name
> SalespersonID
>
> Then a have tblSalesPerson
>
> tblSalesPerson
> ID
> FirstName
> LastName
>
> If i am going to design this, is it best OOP practice to include the
> SalesPersonID within the Company object, or would i create a
> CompanySalesperson object within the company object.
>
> If anyone has a good article to read on this, or can explain it too me,
> i would really really really appreicate it. Ta
| |
| Nemisis 2006-10-31, 7:06 pm |
| Changing the database structure is not an option, i wish it was, i
think it is easier to understand the way that you have described.
A company can only have one salesperson assigned to it, and a
salesperson can be the salesperson for many companies.
| |
| Chris Fulstow 2006-10-31, 7:06 pm |
| Ok, I see your predicament. Your Company objects could each hold a
reference to Salesperson object, and because it's only a reference you
could have more than one Company pointing to the same Salesperson
object.
--
Chris Fulstow
MCP, MCTS
http://chrisfulstow.blogspot.com/
Nemisis wrote:
> Changing the database structure is not an option, i wish it was, i
> think it is easier to understand the way that you have described.
>
> A company can only have one salesperson assigned to it, and a
> salesperson can be the salesperson for many companies.
| |
| Nemisis 2006-10-31, 7:06 pm |
|
Chris Fulstow wrote:
> Ok, I see your predicament. Your Company objects could each hold a
> reference to Salesperson object, and because it's only a reference you
> could have more than one Company pointing to the same Salesperson
> object.
>
Chris,
U will have to forgive me, as i am a bit new to OOP, and not really
sure what you mean there.
The thing that confuses me a lil, is that a company DOES NOT have to
link to a salesperson, so it is optional.
|
|
|
|
|