You are here: Re: Using a Resource as a Class Property « PHP Programming Language « IT news, forums, messages
Re: Using a Resource as a Class Property

Posted by Jerry Stuckle on 07/23/07 12:14

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@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация