|
Posted by Jerry Stuckle on 07/24/07 02:20
Sanders Kaufman wrote:
> Jerry Stuckle wrote:
>> Sanders Kaufman wrote:
>
>>> Also, the idea of doing this:
>>> "$x = new MyObject($y, $z)"
>>> instead of this:
>>> "$x = new MyObject()"
>>> just *feels* wrong to me.
>>>
>>> I'm not sure why - but it's probably legacy cringing from some other
>>> platform and package in my past.
>>>
>>
>> Not at all. The whole purpose of the constructor is to initialize the
>> object. It is probably more common to pass parameters to the object's
>> constructor than not.
>>
>> For instance, the constructor for the mysqli class:
>>
>> mysqli mysqli_connect ( [string host [, string username [, string
>> passwd [, string dbname [, int port [, string socket]]]]]] )
>>
>> If you pass a host, it will try to connect to the host. If you pass a
>> username, it will connect using that username. If password is
>> specified, it will also use that password, etc.
>>
>> If no parameters are specified, then no connection is attempted.
>
> Yeah - I'm totally cool with the fact that some folks use parms in the
> construction, and on a thinky level, I can certainly see where it would
> be handy. But it really feels wrong.
>
> I have the same issue with using voids... although I use 'em, it just
> feels like the same kind of wrong.
>
Actually, it's not that much different than defining a variable and
providing it a value, i.e.
$i = 3;
Of course there isn't any way to define a simple variable in an untyped
language like PHP, but it's still considered good form in typed languages.
About the closes you could come in PHP is defining and initializing an
array, i.e.
$i = array('zero', 'one', 'two');
Not always done, but you get the idea.
>
>>> This looks like something I'm going to have to HEAVILY consider in
>>> the next iteration of the code - abstract classes, interfaces and
>>> function overrides.
>>
>> Yep.
>>
>> I'd also recommend you pick up a decent book on OO in general. It
>> will explain things a lot better than we can here in the newsgroup.
>
> I'm not very good about learning from tutorial books. I get all the way
> through, don't miss a thing, do all of the exercises... and then have no
> idea what I learned.
>
> If I'm gonna learn this stuff, it's gonna be because someone taught it
> to me here and in the OOP groups. I'll probably also draw up a nice
> poster to remind me about Inheritance, Polymorphism, Abstraction and
> Encapsulation.
You still need to look at the books. Sure, you'll have questions. But
a good book will also answer a lot of questions you might have.
And as I said - it's impossible to get into the amount of detail here in
a newsgroup that you can get from a book.
I teach an OO course. It's five days of intensive learning. OO books
are 200-300 pages or more. There's no way we can handle that type of
detail in a newsgroup.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|