I read through the Misko Hevery Guide: Writing Test Code .
I definitely buy dependency injection as a great tool to increase my test ability and use a lot in my code. However, when reading the first part of the manual, “Error # 1: The Constructor Really Works,” I find that I'm still a little fuzzy about how you intend to listen to event events.
Let's say I have a class that, for proper operation, must connect the listener to one of the arguments passed through the injection of the constructor dependency. According to the manual, the constructor should only assign arguments to the member variables and not do other work. In addition, the object must be fully initialized when the constructor completes. However, in this case, I would not consider an object to be fully initialized if it does not require connecting listeners.
As far as I can tell, this requires connecting all the listeners in the builder or factory, although this seems very untied from the object itself and it's easy to get out of sync. Also (at least in the actionscript, which I spend most of my time these days), this will mean that my event listeners can no longer be private, as the factory / builder will have to see them.
What is the best way to handle this? Is there any other option that I'm missing here?
source
share