Hacker News new | ask | show | jobs
by bglazer 4202 days ago
So would a better solution be to use something like:

    public static doSomething(Database db){
        db.write("did something"
    }
2 comments

That's the dependency injection[1] way to do it.

[1] http://en.wikipedia.org/wiki/Dependency_injection

Not 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.

s/static/void/