The mechanism used is what's generally known as a class factory (go look in the Gamma et al big book of patterns for more details).
The Pragmatic Programmers book says "Configuration is better than code". All the stuff you can push down into config files instead of hard-coding is good. This code is a great example of that.
At work we've actually taken a different approach, which is to wrap the classfactory and the general code access inside a custom provider, so we just use the custom provider and it figures out which database it's talking to on the fly.