Factory pattern can return a mock type for testing or a production type, as needed, which makes it possible to unit test the code that uses the produced object.
This quick guide explains it well. Then it improves on it by explaining dependency injection.
Factory pattern can return a mock type for testing or a production type, as needed, which makes it possible to unit test the code that uses the produced object.
This quick guide explains it well. Then it improves on it by explaining dependency injection.
https://github.com/google/guice/wiki/Motivation