Some hints by Krzysztof Grzybek:
- Global and static objects cause implicit dependencies/coupling, thus they break the idea of encapsulation.
- It's hard to reason about them - logical scope for understanding behaviour of these objects is expanded to the whole program.
- It's hard to mock/stub them.
- Global objects pollute the main scope.
Bad:
class Player {
walk() {
this.x = nextDestination.x;
this.y = nextDestination.y;
}
}
Good:
class Player {
walk(destination) {
this.x = destination.x;
this.y = destination.y;
}
}