3 ms·
So would a better solution be to use something like: public static doSomething(Database db){ db.write("did something" }
by bglazer 12y ago
So would a better solution be to use something like:
public static doSomething(Database db){
db.write("did something"
}
- kevan 12y agoThat's the dependency injection[1] way to do it. [1] http://en.wikipedia.org/wiki/Dependency_injection http://en.wikipedia.org/wiki/Dependency_injection
- rverghes 12y agoNot really, because db is not static. In my example, that Database.write() method would itself be static, and thus you can't pass it in as an argument. Basically, this concept means that it's static all the way down, from the top layer to the bottom layer.
- kyllo 12y agos/static/void/