Timeline for Why shouldn't a static class have an internal state?
Current License: CC BY-SA 3.0
9 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Apr 13, 2017 at 12:45 | history | edited | CommunityBot |
replaced http://softwareengineering.stackexchange.com/ with https://softwareengineering.stackexchange.com/
|
|
Dec 11, 2016 at 21:15 | comment | added | Derek Elkins left SE | As additional argument, class-level mutable state and globally visible singletons are forms of ambient authority, whereas the dependency injection approach does not require ambient authority and thus is compatible with the object capability model. This applies to the Service Locator as well; it too can be a form of ambient authority. The aspects that make understanding security tractable in the object capability model make understanding one's code easier. | |
Dec 11, 2016 at 7:57 | history | edited | candied_orange | CC BY-SA 3.0 |
added 2 characters in body
|
Dec 10, 2016 at 21:49 | comment | added | candied_orange | You're welcome. My reason is the same as Fowlers. I like it when I can look at a class and not be able to tell how it gets it's dependencies. I'd rather the class didn't know. Always be careful of what you let a class know about. | |
Dec 10, 2016 at 21:43 | comment | added | amon | Thank you, I hadn't realised that dependency injection is a specific term that only describes particular subset of dependency management techniques. I'm not entirely sure why you think service locators are so unconditionally more terrible than their alternatives (no IoC technique is completely transparent), but that is a discussion for another place. | |
Dec 10, 2016 at 21:08 | comment | added | candied_orange | @amon Service locator is a dependency injection technique? No. No it's not. At best it lets you follow Inversion of control for everything it locates, just not itself. A dependency on the locator gets spread everywhere the need for dependencies that needed locating were located. If you're going to fill my house with garbage I guess it's better if it's one kind of garbage but I'd rather decide for myself what to put in my house. | |
Dec 10, 2016 at 20:46 | comment | added | amon | If I want to use a Singleton, I just relabel it as a “Service Locator” that happens to have a default implementation. That is a viable (and quite widespread) dependency injection technique, though I prefer more explicit techniques like constructor injection. BTW, the GoF note the advantage that “The [singleton] pattern makes it easy to change your mind and allow more than one instance” – once you've already encapsulated the global mutable state, it becomes easier to turn it into local state. | |
Dec 10, 2016 at 20:36 | history | edited | candied_orange | CC BY-SA 3.0 |
deleted 5 characters in body
|
Dec 10, 2016 at 20:29 | history | answered | candied_orange | CC BY-SA 3.0 |