You are here: Re: Constructor as a "Reset" Button « PHP Programming Language « IT news, forums, messages
Re: Constructor as a "Reset" Button

Posted by Sanders Kaufman on 07/24/07 19:17

Andy Hassall wrote:
> On Tue, 24 Jul 2007 18:44:02 GMT, Sanders Kaufman <bucky@kaufman.net> wrote:
>
>> I'm having a BLAST writing this app as OOP as PHP allows. It's one
>> thing to discuss the dance, but it's a thing of beauty to see the
>> performance.
>>
>> I'm noticing that the constructor is a "reset" switch - just like the
>> one on the front of my computer. Calling it seems to just dump all of
>> the old values, free up all of the old resources, and return the object
>> to a pristine state.
>
> Hang on a minute - the constructor is called when creating a new object.
> There's no old values, no old resources - you're creating a new object.

That's ONE use for the constructor.

But as Jerry was telling me in the earlier thread (and which proved true
in my implementation), when that class is the parent of another parent
class, only the most childish constructor gets called.

So, suppose I have clsGrandKid, which "extends" clsKid, which in turn is
an extension of "clsMama".

If clsGrandKid has a constructor, then clsKid's and clsMama's
constructors don't get called - not until I manually call them from
within clsGrandKid.

Furthermore, clsGrandKid can call that constructor any time it likes,
and as often as it likes, returning gramma to a pristine state.

It's just like in real life where a granddaughter just presses a button
and turns her gramma into a little kid again.




> Perhaps you want a singleton class? This often fits well for databases
> resources.

Singleton's aren't really OOP.
They're great for *simulating* OOP, but it's just a cheap knock-off.

 

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

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