[TYPO3-mvc] Benefit of DI when referencing to a class (and not to an interface)?

Roland most.wanted at gmx.at
Tue Jun 26 18:09:40 CEST 2012


thanks.

roland


Am 26.06.12 17:42, schrieb Bastian Waidelich:
> Roland wrote:
>
>>> Yes, it's easier to create unit tests for classes that have less
>>> dependencies.
>
>> do you really reduce dependency with this?
>
> Not literally, but you inverse the control [1] - so instead of creating
> an object, you ask the system for one.
>
>
>> /**
>> * @var Tx_Foo_Domain_Repository_BarRepository
>> * @inject
>> */
>> protected $barRepository;
>
>> aren't you still dependent on a class named
>> Tx_Foo_Domain_Repository_BarRepository?
>
> Right, of course you can't prevent dependency altogether. But you should
> avoid too much of it as it makes code more complex and less reusable
> (think of your notification service - if it has a dependency to your
> BeerEntity, you couldn't reuse it for WineEntities) ;)
> In general try to reduce the knowledge one module needs to have about
> the rest of the system (see [2]).
>
>
>> maybe is should not worry that much about terms and definitions?
>
>
> Right, do what works best for you and the requirements. On the other
> hand it's often a great help to learn something about software patterns
> and principles.
>
>
> [1] http://en.wikipedia.org/wiki/Inversion_of_control
> [2] http://en.wikipedia.org/wiki/Law_of_Demeter
>



More information about the TYPO3-project-typo3v4mvc mailing list