• 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

Design Question: Map Abstraction

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic