How to relate product to category object

  • Thread starter Thread starter J-T
  • Start date Start date
J

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
 
Show me the code for the two classes in question.
Is your collection TYPED ?
 
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
 
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.
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top