|
Posted by Sanders Kaufman on 07/23/07 04:34
Jerry Stuckle wrote:
> Michael Fesser wrote:
>> Quite simple: A base class with a member variable and a method that
>> performs some action with that. Since this is done in the constructor,
>> every child class has to be able to initialize the data before calling
>> the parent constructor, as you can see in B::__construct(). If PHP would
>> automatically call the parent constructor, this would be impossible.
>
> Generally unique to PHP. Java, C++ and SmallTalk all call the base
> class constructor automatically before any code is executed in the child
> class constructor.
OK - to update my understanding...
PHP doesn't automatically call constructors BUT doing so would be more
in keeping with the Tao of OOP.
Zat right?
> Also, the parent should never have a dependency on the child class, and
> the parent's class constructor should never depend on anything in the
> child class other than what is passed to the constructor.
Wow. Cool. When I built my classes, I didn't KNOW it should be done
that way, but it FELT right.
I seriously considered writing the classes in a way to where the parent
would *presume* all kinds of stuff about the child, but it didn't jibe
with my obsession with atomicity - so I didn't do it.
Navigation:
[Reply to this message]
|