Hi, I am learning ZF2 and discovering all the DI part. I have just watch the zend webinar about writing testable code at http://www.zend.com/en/webinar/PHP/70170000000bk4b-testablecode-20120315.flv (i am starting with all that testing things too ...)
At minute 30, it says : - Never use static access - Always inject dependencies - Maybe use a dependency injection container At minute 41, it says : - Do not pull dependencies ... - ... push them - Do not reach through objects In the exemple the class constructor has a registry parameter and one of the class methods use this registry to get a http_client and call a webservice with it. This illustrates the "Do not reach through objects", as the class reach the http_client through the registry. In ZF2 i see a lot of code exemple that make use of the Locator to get other objects, like in the last article from Rob Allen : $locator = $application->getLocator(); $view = $locator->get('Zend\View\View'); $jsonStrategy = $locator->get('Zend\View\Strategy\JsonStrategy'); I am wondering in how this could be different from the exemple of the webinar, as here the $view object is reached through the locator. Is there particular use case where the locator can be use safely and other case where it should be avoided ? I am thinking maybe in the Rob Allen's exemple you don't unit test this kind of method but have "fonctional test" for it so you don't really care about that ? Thanks for your enlightments Tom -- View this message in context: http://zend-framework-community.634137.n4.nabble.com/Question-about-DI-and-OOP-good-practice-tp4519848p4519848.html Sent from the Zend Framework mailing list archive at Nabble.com. -- List: fw-general@lists.zend.com Info: http://framework.zend.com/archives Unsubscribe: fw-general-unsubscr...@lists.zend.com