The Artima Developer Community
Sponsored Link

Java Buzz Forum
Two Picocontainer Idioms

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Brian McCallister

Posts: 1282
Nickname: frums
Registered: Sep, 2003

Brian McCallister is JustaProgrammer who thinks too much.
Two Picocontainer Idioms Posted: Aug 23, 2004 2:13 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Brian McCallister.
Original Post: Two Picocontainer Idioms
Feed Title: Waste of Time
Feed URL: http://kasparov.skife.org/blog/index.rss
Feed Description: A simple waste of time and weblog experiment
Latest Java Buzz Posts
Latest Java Buzz Posts by Brian McCallister
Latest Posts From Waste of Time

Advertisement

Two idioms I have found very useful when working with Picocontainer:

When you refactor a component to add a dependency (new constructor arg), leave the old constructor signnature, but have it pass a null object (not null!) to the new constructor. The null object throws an exception (I like UnsupportedOperation or IllegalState personally) if anything on it is called. This solves the annoying "I don't want to add the dependency because it will break the unit test compiles" problem (side note, setter injection people like to argue that si does this for free. Really, you just get a partially initialized component, not a solution). As pico uses the greediest constructor it can find, it will use the new one.

The second idiom is using a Component and ComponentConfig where the ComponentConfig is a simple bean which holds the primitive (Strings are primitive in Java, darn it) dependencies. If you really like your XML you can use xmlbeans to generate the config classes and read them at runtime. I don't. Avoid the pull of putting all the config values in a single big config class which everything is dependent on. The phrase "everything is dependent on" should be sufficient to stop you, right there.

Read: Two Picocontainer Idioms

Topic: [Aug 12, 2004 10:24 PDT] 21 Links Previous Topic   Next Topic Topic: Giving away attributes without all of your source

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use