[TYPO3-team-core-v5] Constructors and interfaces

Christopher Hlubek bruno.bolzano at gmail.com
Mon Sep 22 12:38:13 CEST 2008


I stumbled upon the same problem with constructors in interfaces and
mock objects. In my opinion defining constructors in interfaces is not
good and shouldn't be used at all. The interface should be the most
general "contract" for an API. At least for the methods that can be
called for an object of that type publicly. Defining a constructor in
an interface will only restrict the implementation to a particular
constructor. When instantiating a class with "new", you will directly
use the constructor of the implementation and don't have to care about
the interface. And the interface won't help you either.

I think a constructor is and should be implementation specific.

So +1 for getting rid of constructor declarations in interfaces.

Grettings,
Christopher

2008/9/22 Andreas Förthner <andreas.foerthner at netlogix.de>:
> Hi all,
>
> today I stumbled over a problem with mock objects once again. The problem
> ist, that you cannot mock an interface that has a constructor defined. If
> you try, you get a PHP error. Of course it might be useful to define a
> constructor in an interferace, but it is also a very important task to mock
> interfaces, without that unit testing is mostly not possible.
>
> What do you think about removing constructor definitions from interfaces? Or
> are there any plans to make mock objects work with that in phpunit?
>
> Would be great to hear your opinions.
>
> Greets Andi
>
>
>
>
>
> _______________________________________________
> TYPO3-team-core-v5 mailing list
> TYPO3-team-core-v5 at lists.netfielders.de
> http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-team-core-v5
>
>


More information about the TYPO3-team-core-v5 mailing list