Sun has always felt a need to educate its developers. Sometimes this has led to Pearl Harbour scale disasters like J2EE, but it has also produced an extremely technically literate community. On the other hand, sometimes you wish Microsoft didn’t even try. I’ve pretty much come to the conclusion, for instance, that the Microsoft Enterprise Library is the Wrong Thing. Every so often, we come across stuff which falls under the heading of “mistakes you need a PhD to make”, as Francis Fukuyama describes his advocacy of the invasion of Iraq. The provider pattern is top of my list here. If you’re not familiar with this, it’s a Microsoft-specific form of pluggable singleton. It’s a singleton by virtue the “default provider” mechanism. It’s extremely over-complex and, in my experience, just plain doesn’t deliver any benefits that plain old using constructors wouldn’t achieve better.
By combining the singleton pattern with a pluggable architecture, they hoped to draw the poison from the pattern. Anyone who’s used it will know this isn’t the case.
- Sometimes the pluggability just plain fails: try find the parent node from a plugged sub-sitemap.
- Sometimes its insistence on using concrete types for everything makes your code nigh-on impossible to implement (especially if some third party made the same decision…)
- Since it’s a singleton and hence can have shared state, you need to be writing thread-safe code. Not a trivial task for a neophyte developer who just wanted a bit of pluggability.
- Since it doesn’t have a coherent dependency injection model, you often end up using the Microsoft configuration model to get anything done. (You do get a set of string name/value pairs, but any complex dependencies will fall down badly.)
- Worst, when you finally discover that you actually wanted two of something, you get reminded that the provider pattern remains a special case of the singleton pattern.
It is in many ways really impressive, but that’s what makes it especially pernicious: it picks up a lot of developers who are trying to improve and leads them down blind alleys. You can spend a lot of time supporting a provider pattern. When you start to figure out that it’s not really paying back the investment, you’re going to feel that much of this patterns stuff is just nonsense. Tell me you don’t know a developer like that…
Ironically, you know one really obvious user of the provider pattern? Subtext, the blogging engine that powers, um, this site…