In OO languages, is it a code smell if I find myself passing the same parameter to every single object?

I'm making a tool to manage an ebook library. I have a Book class with hundreds of instances. Every single time I create one, I pass it the same SQLite database as a parameter, so that it can do save, update, etc operations on itself.

It seems like this is kind of a code smell. If I'm ALWAYS passing the exact same parameter, then surely I shouldn't be passing that as an argument at all, it should be hardcoded somewhere, right?

But I'm not sure how to implement it.

Posted Jan 5, 2017, 11:03 PM UTC

08
Loading comments…