On 19 September 2011 10:17, Etienne Kneuss <col...@php.net> wrote: > Hi, > > 2011/9/19 Frédéric Hardy <frederic.ha...@mageekbox.net> > >> Hi ! >> >> What is the utility of abstract method if implementation can not follow >> the signature (constraints ?) of the abstract method ? >> > In this case, abstract methods are totaly useless ! >> Moreover, i think that it's not compatible with Liskov substitution >> principle. > Subclasses can loosen the preconditions, that's eactly what happens here and > it is perfectly fine in theory.
WOW. I really didn't expect this as a response to what, for me, was quite an innocent question. Normally I get a 3 comments pointing me in the right direction and I'm happy. Maybe its me. But something that is abstract certain implies to me a loose idea. The keywords have inherent meaning. At least in English. If a class, abstract or otherwise, has the requirement to have an enforced parameter list for a method, then would seem to be the role of an interface. An abstract class and an method declared in an interface, both require implementation. But with an interface, you are not able to change the parameters. would seem to satisfy LSP. Unless you use an interface to enforce the parameter order, how else do you guarantee the contract? If you also enforce the parameters for other methods (abstract or otherwise - I'm still not 100% on the reason for the difference - or, at this stage, if there even is a difference), then interfaces are seemingly redundant. Take the following code ... <?php abstract class abstractBase { abstract public function __construct($a, $b); } class ConcreteBase extends abstractBase { public function __construct($a, $b, $c = null) { } } class SuperCrete extends ConcreteBase { public function __construct($a, $b, $c, $d = null) { parent::__construct($a, $b, $c); } } $cb = new ConcreteBase(1,2); $sc = new SuperCrete(1,2,3); ?> The signatures here feel completely right, though MAYBE one could argue that SuperCrete's constructor is off because $c is not optional. I don't think $a and $b can ever become optional or missing from any sub-class' definition. As things stand, 5.4.0-beta doesn't report any problem with this code. Have I made a mountain out of a mole hill? (http://en.wikipedia.org/wiki/Make_a_mountain_out_of_a_molehill for those who don't know the English idiom). -- Richard Quadling Twitter : EE : Zend : PHPDoc @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php