• Post Reply Bookmark Topic Watch Topic
  • New Topic

object design  RSS feed

 
hong ye
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a question about object design. I want to create a "Item" class which belongs to different Categories and Subcategories.

My question is : do I need to create list of Categories and Subcategories inside to Item class and what is right approach?

Class Item {

String id;
List category = new ArrayList();
List subCategory = new ArrayList();

...

}

or

Class Item {

String id;
String category;
String subCategory;
....

}

which way is better?

Thanks


 
srinivas srinivasmeenavalli
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's depending on situation or datastructure.
For example one Item related to multiple Categories and Subcategories ( one to many relationship)
your first approach is better.


in other case if one Item related to a Category and Subcategory ( one to one relationship)
your second approach is better.


judge based on the requirement
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!