In my Abstract Factory post, I mentioned that I really don’t like the pattern, and in particular, code like this:
One of the comments mentioned that this might no be ideal, but it is still better than:
And I agree. But I think that, as the comment mentioned, a far better alternative would be using the container. You can do this using:
Then you just need to wire things through the container. Among other things, this means that we respect the open / closed principle. If we need to support a new system, we can just add a new class, we don’t need to modify code.
Remember, the Go4 book was written in the age of C++. Reflection didn’t exists, and that means that a lot of patterns do by hands things that can happen automatically.