Re: Using a Resource as a Class Property
- From: Jerry Stuckle <jstucklex@xxxxxxxxxxxxx>
- Date: Mon, 23 Jul 2007 08:14:59 -0400
Sanders Kaufman wrote:
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?
That is true. And perhaps one day PHP will more closely follow the OO way of doing things. They've been getting closer with each release.
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.
The child class defines the derivation, and therefore knows it has a parent class (and some things about that parent). However, the parent doesn't know if (or when) it is being used as a base class, so it should never assume things which may or may not be there (or set).
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.
- Follow-Ups:
- Re: Using a Resource as a Class Property
- From: Sanders Kaufman
- Re: Using a Resource as a Class Property
- References:
- Using a Resource as a Class Property
- From: Sanders Kaufman
- Re: Using a Resource as a Class Property
- From: Michael Fesser
- Re: Using a Resource as a Class Property
- From: Sanders Kaufman
- Re: Using a Resource as a Class Property
- From: Michael Fesser
- Re: Using a Resource as a Class Property
- From: Sanders Kaufman
- Re: Using a Resource as a Class Property
- From: Michael Fesser
- Re: Using a Resource as a Class Property
- From: Sanders Kaufman
- Re: Using a Resource as a Class Property
- From: Michael Fesser
- Re: Using a Resource as a Class Property
- From: Sanders Kaufman
- Re: Using a Resource as a Class Property
- From: Michael Fesser
- Re: Using a Resource as a Class Property
- From: Jerry Stuckle
- Re: Using a Resource as a Class Property
- From: Sanders Kaufman
- Using a Resource as a Class Property
- Prev by Date: Re: newbie: include_path error
- Next by Date: Re: Using a Resource as a Class Property
- Previous by thread: Re: Using a Resource as a Class Property
- Next by thread: Re: Using a Resource as a Class Property
- Index(es):
Relevant Pages
|