> From: Soenke Ruempler [mailto:ruempler@topconcepts.com]
> BUT let derived constructors change parameters
> a) as constructors are never called from the parent, but
> optionally from a child class, it's completely valid IHMO
> b) constructors are usally not used in object aggregation /
> setters, but called only _ONCE_ at object creation => the
> creating code knows the exact (sub-)class and it's constructor.
You gave the reason why the restrictions don't apply for constructors
(also not in PHP) and probably nobody will change that for "academic
reasons" :)
Constructors are the special case in OOP as you can call constructors
only by instantiating classes. When using them you always refer to a
concrete class and never have to deal with polymorphic subtypes (of
course constructors can be overloaded in languages that support it).
Thus constructors are a place where differences between subtypes tend to
pile up so that the LSP holds for the rest of the inherited methods.
If you *want* to enforce constructor signatures PHP allows for defining
them in interfaces which makes no sense from the academic pov, but may
be useful when using the PHP feature of "new $classname($arg)" where you
want to make sure first that "$classname instanceof
ISomehowConstructable" (where instanceof must take a string as the first
operand and work accordingly).
Regards,
Matthias