Win a copy of Head First Android this week in the Android forum!
  • 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 ...
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Al Hobbs
  • salvin francis

spring - declarative collections

Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I am new to spring, we have a requirement
that we would like to change our java data
structures declaratively (configurable).

i.e , we have implemented data feeds, queues
using PriorityQueue, Synchronized Hashmaps, vectors

will spring framework give me an option to inject (instantiate)
these collections classes dynamically.
I mean , if we need to change to PriorityBlockingQueue, and change
Hashmaps to hashtable and vectors to Synchronized ArrayLists

i would greatly appreciate if someone can give some pointers
if this is supported by spring framework.

Many thanks,
Abdul Aleem
Posts: 16631
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Spring can help ease the pain. Here are some suggestions:

1. Program to interfaces; use interfaces or abstract types for your method/constructor parameters. Spring can inject any type of object as long as it is assignment compatible with the receiving method/constructor parameter's type. If you do this, it will be easier to switch out implementations.

2. Take advantage of Spring's built-in collection injection support for injecting lists, maps, sets, and properties.

3. If things start to get ugly, try using the Adapter pattern. Create an Adapter that can accept one or more of the natively supported collections and then inject the adapter into the target class. The target class then uses the adapter to get whatever type of collection it needs. The adapter does the transformation from simple collection to custom collection. This should probably be considered as a last resort. Strive to keep your code simple using 1 & 2 above.
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic