I read about dependency injection, and I understand the basic concept that a method should get what it needs from its caller, and not create such elements themselves. As a result, new operators can be completely excluded from the method (some basic objects would be excluded, of course, I found one example of this for things like StringBuilder that seem crazy to them, go).
My question sounds deceptively simple, but I suspect that the answer is actually quite complicated: where do all the new operators go?
The answer at first seems simple: the new operator just gets into a method that calls a method that needs this object. The problem with this, however, is that the calling method is probably also under testing, and so new gets the calling method from the calling method until you get to the root method (which at the moment seems crazy unchecked) , which creates an obscene amount of objects to use at different points in the call stack. The situation becomes even more complicated when you consider that this root method is the root of a large number of other methods, so for every opportunity you need to create objects. This also poses a performance problem, as you quickly end up with a large number of objects that are never used, but which should be created anyway "just in case".
It’s quite obvious to me that I missed some important knowledge that is so obvious to other developers that no one thinks to describe on the blog. However, I obviously don’t know what I don’t know, so I humbly ask that I be secret: where do all the new operators go?
I should mention that I am developing PHP, so every request starts from the same point, and it looks like this "root" method in index.php should cover everything the application can do to ensure it provides an object for everything. what will he do in the current request. Again, a fundamental misunderstanding arises here, and I really really want to fix it.
source share