473,324 Members | 2,254 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,324 software developers and data experts.

Class design for a many to one relationship

RSH
Hi,

I have a situation where I have a class Employee.

Each Employee can have multiple Deductions - I have a deduction class.

I have set the relationship up as a "has-a" relationship.

My question is what is the proper way to setup a situation where each
employee may have multiple deductions? Is it a situation where I simply add
a Deduction collection in the Employee class which stores deductions? ...or
do I have a seperate class that manages the collections so basically I would
have an Employee class, a Deduction Manager class, and a deduction class?

Thank you for any insight you might be able to provide.
Ron



Oct 8 '07 #1
5 1632
RSH,

I would just use some sort of collection, or better yet, a dictionary
that is keyed on whatever unique identifier you use for each deduction.
Then, I would expose a property on the deductions class called Deductions
and expose that dictionary.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"RSH" <wa*************@yahoo.comwrote in message
news:eq****************@TK2MSFTNGP03.phx.gbl...
Hi,

I have a situation where I have a class Employee.

Each Employee can have multiple Deductions - I have a deduction class.

I have set the relationship up as a "has-a" relationship.

My question is what is the proper way to setup a situation where each
employee may have multiple deductions? Is it a situation where I simply
add a Deduction collection in the Employee class which stores deductions?
...or do I have a seperate class that manages the collections so basically
I would have an Employee class, a Deduction Manager class, and a deduction
class?

Thank you for any insight you might be able to provide.
Ron


Oct 8 '07 #2
RSH
Nicholas,

Thanks for the reply!

So Im understanding that I would use a class Deductions to act as the
collection that sits "between" the deduction and employee?

Thanks!
Ron
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:6A**********************************@microsof t.com...
RSH,

I would just use some sort of collection, or better yet, a dictionary
that is keyed on whatever unique identifier you use for each deduction.
Then, I would expose a property on the deductions class called Deductions
and expose that dictionary.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"RSH" <wa*************@yahoo.comwrote in message
news:eq****************@TK2MSFTNGP03.phx.gbl...
>Hi,

I have a situation where I have a class Employee.

Each Employee can have multiple Deductions - I have a deduction class.

I have set the relationship up as a "has-a" relationship.

My question is what is the proper way to setup a situation where each
employee may have multiple deductions? Is it a situation where I simply
add a Deduction collection in the Employee class which stores deductions?
...or do I have a seperate class that manages the collections so
basically I would have an Employee class, a Deduction Manager class, and
a deduction class?

Thank you for any insight you might be able to provide.
Ron



Oct 8 '07 #3
RSH,

If you want. Unless you have some sort of special code that corresponds
to the collection that the Employee class can't handle, then I would use a
separate class, otherwise, I would just use a List<Tor Dictionary<TKey,
TValue>.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"RSH" <wa*************@yahoo.comwrote in message
news:O3**************@TK2MSFTNGP03.phx.gbl...
Nicholas,

Thanks for the reply!

So Im understanding that I would use a class Deductions to act as the
collection that sits "between" the deduction and employee?

Thanks!
Ron
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:6A**********************************@microsof t.com...
>RSH,

I would just use some sort of collection, or better yet, a dictionary
that is keyed on whatever unique identifier you use for each deduction.
Then, I would expose a property on the deductions class called Deductions
and expose that dictionary.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"RSH" <wa*************@yahoo.comwrote in message
news:eq****************@TK2MSFTNGP03.phx.gbl...
>>Hi,

I have a situation where I have a class Employee.

Each Employee can have multiple Deductions - I have a deduction class.

I have set the relationship up as a "has-a" relationship.

My question is what is the proper way to setup a situation where each
employee may have multiple deductions? Is it a situation where I simply
add a Deduction collection in the Employee class which stores
deductions? ...or do I have a seperate class that manages the
collections so basically I would have an Employee class, a Deduction
Manager class, and a deduction class?

Thank you for any insight you might be able to provide.
Ron



Oct 8 '07 #4
On Oct 8, 11:26 am, "RSH" <way_beyond_o...@yahoo.comwrote:
Hi,

I have a situation where I have a class Employee.

Each Employee can have multiple Deductions - I have a deduction class.

I have set the relationship up as a "has-a" relationship.

My question is what is the proper way to setup a situation where each
employee may have multiple deductions? Is it a situation where I simply add
a Deduction collection in the Employee class which stores deductions? ...or
do I have a seperate class that manages the collections so basically I would
have an Employee class, a Deduction Manager class, and a deduction class?

Thank you for any insight you might be able to provide.
Ron
I would design a class for the Deductions (assuming the definition of
a Deduction is more than one field), call it say clsDeduction. Then in
the Employee class, I would make a proeprty Deductions that is a
List<clsDeductioncollection.

Oct 8 '07 #5
RSH wrote:
So Im understanding that I would use a class Deductions to act as the
collection that sits "between" the deduction and employee?
I believe that Nicholas may have meant to write "expose a property on
the Employee class", rather than "expose a property on the deductions
class".

The advantage of using a Dictionary as he suggests is that if you have
some sort of key associated with each type of deduction, it's easy to
retrieve a specific deduction from an employees collection of deductions
(or to find that it's not present, of course).

But you don't need a new deductions class to take advantage of that, and
based on Nicholas's follow-up post, I'm guessing he didn't really mean
for you to create one, if a Dictionary by itself suffices (and it
probably would).

Pete
Oct 8 '07 #6

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

Similar topics

13
by: Bryan Parkoff | last post by:
I have created three classes according to my own design. First class is called CMain. It is the Top Class. Second class and third class are called CMemory and CMPU. They are the sub-classes....
0
by: nin234ATIyahoo.com | last post by:
I am wondering what is a good design pattern in terms of C++ class relationship for the problem I am trying to solve. template<class DbKey, class DbVal, class DbTag> class srvBerkDB : public Db...
6
by: JSheble | last post by:
I come from a Delphi background, and am currently trying to port or convert some of our Delphi classes to C#. I've got a good handle on basic class design, but am a bit lost with some of the more...
19
by: Chocawok | last post by:
Some of the classes in my app are graphical. To encapsulate the graphical side of things I had created a class called "sprite" which holds a bit map and knows how to draw itself etc. The...
11
by: Darren.Ratcliffe | last post by:
Hi guys Posted what was probably a rather confusing post about this the other day, so I am going to have another go and see if I can make more sense. This sis purely a I've got a base class...
3
by: Steven | last post by:
Hello All, I am relatively new to database design and wanted to ask a few questions to see if I am on the right track regarding design and normalization. I am creating a user entity which is...
6
by: JoeC | last post by:
I have a question about designing objects and programming. What is the best way to design objects? Create objects debug them and later if you need some new features just use inhereitance. Often...
2
by: Joseph Geretz | last post by:
When I create a Form, the VB IDE creates the following files in the following hierarchy: Form1.cs Form1.Designer.cs Form1.resx Both Form1.cs and Form1.Designer.cs are partial implementations...
3
by: Ravi | last post by:
Is this the correct way to think of "base class"? The "base class" is a class from which other classes are derived. The "base class" will never be derived from another class.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.