The global DatabaseManager class makes it difficult to do testing using dependency inversion.
- Properties are read from a file rather than providing them to the manager.
- The singleton pattern makes it difficult to load different databases for different tests or to create and delete a database for a test.
- It forces the same database to be used for both testing and development.
- It forces tests to use introspection to implemented desired behavior at runtime.
- It encourages the exposure of a dangerous endpoint (
clear) in order to enable testing.
Most implementations are already passing a DataAccess object around and so there is little value in a DatabaseManager singleton. We should just initialize the DataAccess object with the desired DatabaseManager. Then a test could provide a mocked database version if desired, or set up and tear down a test database. You could get rid of the clear endpoint.
The global DatabaseManager class makes it difficult to do testing using dependency inversion.
clear) in order to enable testing.Most implementations are already passing a DataAccess object around and so there is little value in a DatabaseManager singleton. We should just initialize the DataAccess object with the desired DatabaseManager. Then a test could provide a mocked database version if desired, or set up and tear down a test database. You could get rid of the
clearendpoint.