Timeline for Please explain the "swapable dependency" arguments for IOC containers
Current License: CC BY-SA 4.0
11 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jul 25 at 6:54 | comment | added | Euphoric | This is the right answer. @ScottyJamison As for "spilling the guts of the library" That is indeed risk that you, as library developer need to consider. Expanding API surface to give users of your library/framework more flexibility must be weighted against risk of creating bad API and getting stuck with it. It is also why API design is such a big deal. | |
Oct 4, 2023 at 0:16 | comment | added | Ewan | well, as flater points out, Bob, Jane and Freddie can be you, future you and you on a second program that's part of the same project. But when you don't like a popular thing, you have to ask yourself why. We all know why DI is good, there are a million blog posts about how great it is. There's something in your in your head that makes you not like it. But if you don't, then how do you solve the problem I outline? event handlers? is that better?... is it even different? | |
Oct 3, 2023 at 22:26 | comment | added | Scotty Jamison | I guess I've always envisioned "inversion of control" as something that happens within a project - i.e. an implementation detail to help with organization. Having it happen across the public API as well, by default, seems like we're spilling the guts of our program and making all sorts of private implementation-detail-classes into public details. But, you're right, I did not ask for if it was a good or bad idea, just what it meant :) | |
Oct 3, 2023 at 22:13 | comment | added | Flater |
@ScottyJamison: Interesting learning point. You said "their classes can be custom-wired-up by the library consumer" Re-read the name "inversion of control". The implication of that name is that it's usually the designer who controls who has which dependency (i.e. whoever wrote Calculator decided that it will use Logger ), and IOC inverts that control so that it's the consumer who controls who uses which dependency (i.e. the consumer can inject any ILogger that they want to). I'm not adding new information here but I hope this make the name "inversion of control" seem less mystical.
|
|
Oct 3, 2023 at 22:13 | comment | added | Ewan | remember your question was "what exactly do these people mean when they say they need to "support multiple different types of loggers'?", not "is it good to support multiple types of loggers?" | |
Oct 3, 2023 at 22:10 | comment | added | Ewan | if you add Flush() to the interface, and the consumers get the new version of your class, they can then update their own implementations and everything works. Yes it would be a breaking change, but so what? | |
Oct 3, 2023 at 21:52 | comment | added | Scotty Jamison |
If I want to add a new Flush() method to the logger class and interface, then any end-user who was trying to implement my Logger interface would need to update their classes to include Flush() as well, which is why its a breaking change. If my library only has a couple of explicit and intentional places that support this kind of "class swappability", then that seems fine, but if every single class is intended to be substitutable by the end user if they so wish, then that seems bad.
|
|
Oct 3, 2023 at 21:06 | comment | added | candied_orange | @ScottyJamison both the author and consumer adding new methods doesn't prevent backwards compatibility. Just means you each need your own namespace. | |
Oct 3, 2023 at 20:47 | comment | added | Scotty Jamison | Interesting perspective. So, are you suggesting that a library makes it so pretty much all their classes can be custom-wired-up by the library consumer? That means, as the library author, I can never add new methods to any existing class/interface without it being considered a breaking change, since someone could be swapping out my class for their own and their class may not conform to the updated interface? So we're giving tons of flexibility to the library consumer, just in case they need it, but we're also making the library itself extremely rigid. | |
Oct 3, 2023 at 20:11 | history | edited | Ewan | CC BY-SA 4.0 |
added 429 characters in body
|
Oct 3, 2023 at 19:58 | history | answered | Ewan | CC BY-SA 4.0 |