Sep 7, 2018 · 1 min read
Nice article. I only disagree with the point that it is a disadvantage of the factory pattern that you cannot tell from which factory an object came. We should be creating loosely coupled, and therefore maintainable architectures. The key technique for this is to _not_ make the origin of an object part of the contract between producer and consumer. (The analog in a statically typed language is to declare the type of objects passed as parameters as interfaces rather than classes, to avoid tight coupling.) If one really _must_ remember the origin of an object — which is a code smell — one can still have the factory “tag” the objects.