• Post Reply Bookmark Topic Watch Topic
  • New Topic

Design Question: Map Abstraction  RSS feed

 
Aryeh Golob
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a general design question regarding map implementation.

I have a class that sorts products based on defined criteria. The problem is that the criteria are VERY generic and require varied Map implementation.

Here is Map declaration ...



Sorting Criteria:

~ Predefined order: (ex: IPod's, IPod Accessories, IPod Cases, IPod Cables). Categories are pre-defined items are inserted in specific order. Note, inner map represents a sort string, so SortedMap is applicable.

~ Alphabetic Order: (ex: Apple Computers, Dell Computers, HP Computers. etc).

~ No Order required

My approach is to check for formatting data and instantiate Map with appropriate class (HashMap, LinkedHashMap, TreeMap).

Here is sample code ...



Data is only advertised as a Map to the outside world, but internal function will work based on format requirements.

Is this good Java design, or is there a better way?

Input is appreciated!

Thanks,
Aryeh
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!