I'm writing a handy library (we'll call it Thinger) that goes off and fetches an XML document, does some X-Path query on it and does something helpful with the result of that. (What I'm actually doing is far too boring to bother you all with, this is just a simplified example.)
Because I'm a wise and lazy programmer I'm making use of two third-party components, one for fetching remote XML documents (we'll call it Fetcher) and one for running X-Path queries (we'll call it Querier).
My library provides a Thinger class, into which one must inject a Fetcher and a Querier. I could do this via setters or a constructor.
But then I think about the poor people using my library, who now have to think about injecting my dependencies when all they really want to do is call something like
So far, I have written a static factory which instantiates a new Thinger, Fetcher and Querier, assembles them as appropriate and returns the Thinger.
That left me feeling slightly unclean.
Surely there's a better way?
Most frameworks etc would probably get around this using a Dependency Injection Container or similar, but since I'm writing a fairly small third party library that seems like a bad approach.