471,334 Members | 2,221 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

How to relate product to category object

J-T

Hello All,

I have two objects one is Product and the otherone is the Category. Category
object is like Food,books,Medicine and etc which has different tax rates .
My product object has properties like name ,price , CategoryID. I need to
create a collection of my products and in this collection I want to have the
Categories tax rate too? How can I relate these two objects together?

Thanks
Feb 9 '06 #1
4 1851
Show me the code for the two classes in question.
Is your collection TYPED ?

Feb 9 '06 #2
J-T
this is my Product object :

public class Product
{
private string m_name;
private double m_price;
private Boolean m_imported;

public Product(string name, double price , Boolean imported)
{
m_name = name;
m_price = price;
m_imported = imported;
}

public string Name
{
set
{
m_name = value;
}
get
{
return m_name;
}
}

public double Price
{
set
{
m_price = value;
}

get
{
return m_price;
}
}

public Boolean Imported
{
set
{
m_imported = value;
}

get
{
return m_imported;
}
}

}

I have not completed the category object ,but here is what I written so far
(which is incomplete)

public class Category

{

private enum Categories {Food=1,Books=2,Medical=3,others=4};
}
As you can see I am trying to create a collection later on . maybe I have to
combine these two classes ,but I don;t know how.

Thanks

"Steven Nagy" <le*********@hotmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
Show me the code for the two classes in question.
Is your collection TYPED ?

Feb 9 '06 #3
Could I suggest that you use dataTables instead?
One datatable for each class.
Then, add them to a dataset. You can also define the relationship in
the dataset as well.
Otherwise, try something like this:
Add all your Categories to a collection in the same order that they
appear in the enumeration.
Make the collection a public static variable somewhere you can get to
from your Product class.
Then remove the enum all together from categories.
Add a property to your product class called CategoryID
Add a readonly property to your Product class of type Category. In the
GETTER for the property, check the products CategoryID, and retrieve
the relevent position from the Category collection.

This is kind abstract, but hopefully points you in a useful direction.

Feb 9 '06 #4
J-T
Steven,

Thanks a lot for your help, I will give a try tomorrow (it is 1:00 AM
here:-)) and if there is any moe questions I will let you knw. Thanks for
the help

"Steven Nagy" <le*********@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Could I suggest that you use dataTables instead?
One datatable for each class.
Then, add them to a dataset. You can also define the relationship in
the dataset as well.
Otherwise, try something like this:
Add all your Categories to a collection in the same order that they
appear in the enumeration.
Make the collection a public static variable somewhere you can get to
from your Product class.
Then remove the enum all together from categories.
Add a property to your product class called CategoryID
Add a readonly property to your Product class of type Category. In the
GETTER for the property, check the products CategoryID, and retrieve
the relevent position from the Category collection.

This is kind abstract, but hopefully points you in a useful direction.

Feb 9 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by J-T | last post: by
reply views Thread by David Troxell - Encourager Software | last post: by

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.