I have a singleton object, that handles database stuff for my application, but I would like to have a similiar class to be used during testing, so that I can have many smaller test databases that dont interfere with each other.
I could just drop the singleton and just create a new instance of the database class at startup, but that would mean I'd have to pass around this instance to everywhere where database actions are needed and I dont want that.
I could make a singleton that would work as an interface to a single instance of the database class. Someting like this:
object DB{
val db = new Database()
def set(a:Int,b:Int) = db.set(a,b)
def get(a:Int) = db.get(a)
}
This just feels sort of stupid and pointless, especially when the database class is fairly big and I'd have to do that to all of the methods. Is there a better way to solve this problem?
Thanks!
object DBand the test versions of it?