• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

object design

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Lookout! Runaway whale! Hide behind this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic