473,387 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

OOP relationships. Advice needed!! PLEASE

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

Oct 31 '06 #1
5 1018
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" <da*********@hotmail.comwrote in message
news:11*********************@e64g2000cwd.googlegro ups.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

Oct 31 '06 #2
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<SalesPersonsalespeople;

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
Oct 31 '06 #3
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.

Oct 31 '06 #4
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.
Oct 31 '06 #5

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.

Oct 31 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Xenophobe | last post by:
I have a popup window (required by the client) containing a form and would like to prevent users from accessing it directly. They are instead required to access the page via a hyperlink on another...
9
by: Rick Muller | last post by:
I have a problem that I would like to get some advice on from other Pythonistas. I currently manage a (soon to be) open source project for displaying molecular graphics for a variety of different...
0
by: PCC | last post by:
I am writing an ASP.NET web application and I control all the tiers. I need to return all results from the Web Service mid-tier as XML so other people can use our business objects in the future if...
2
by: WStoreyII | last post by:
This question is for all of the developers out there. I recently had to drop out of school as it was getting way to expensive and i just could not pay it. I am really upset about this becuase i...
2
by: mesut demir | last post by:
Dear collegeaus, I would like to learn Visual Basic.NET and working with DATABASES. My intention is making some Windows programs using Database & Internet programs using Databaseses.(SQL) ...
0
by: SerbianEagle | last post by:
Hello. I've just joined this forum as I've been searching for some advice with a data conversion that I have to do. Using : MS SQL server 2000 Old DB: many tables and no relationships...
23
by: JohnH | last post by:
I'm just recently come to work for an auto brokerage firm. My position involves performing mysterious rites, rituals and magick in order to get information out of their access database. This is...
8
by: STG | last post by:
Greetings, My group has an SDK that was developed 5 years ago with VC++ 6. Over the last years, the requests for a VS.NET SDK has reached critical mass and I am now in the process of doing that....
2
by: =?Utf-8?B?QmlnU2Ft?= | last post by:
I hope I'm in the correct forum. Please advise if I need to move this question. I've a lead developer who insists on developing with classic ASP & VB6. He & his team have created an impressive...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.