|
Posted by Jerry Stuckle on 07/25/07 00:30
Sanders Kaufman wrote:
> 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.
>
As Andy said - that should be the ONLY USE for the constructor. If you
need to reinitialize the object, create a reinitialize() function.
> 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.
>
True. But it is the child class's responsibility to call the parent
class's constructor - which it should ALWAYS do. Other languages do it
automatically; PHP is lagging in this respect.
> 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.
>
But they NEED to get called.
> Furthermore, clsGrandKid can call that constructor any time it likes,
> and as often as it likes, returning gramma to a pristine state.
>
No, that's NOT the purpose of a constructor!
> It's just like in real life where a granddaughter just presses a button
> and turns her gramma into a little kid again.
>
>
Not at all the same.
>
>
>> 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.
Yes, singletons are quite OOP.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|