|
|
|
|
|
by kentonv
3991 days ago
|
|
> I'm not sure how... pass it around is 'better' than global scope. - Readability: You can see what components use the thing by following the variable as it is passed around. - Testability: Tests can pass in a mock thing. - Maintainability: If you discover someday that you need two different instances of the thing to pass into two different subsystems, you can do that. (This happens a lot, and programmers are really bad at foreseeing it.) - Security: Only the components to which you've passed the thing can possibly use it (subject to the memory safety guarantees of your language). http://www.object-oriented-security.org/lets-argue/singleton... |
|