Login | Register
My pages Projects Community openCollabNet

propel
Reply to message

* = Required fields
* Subject
* Body
Attachments
Send reply to
Topic
Author (directly in email)
Please type the letters in the image above.

Original message

Author Alan Pinstein <apinstein@mac.com>
Full name Alan Pinstein <apinstein@mac.com>
Date 2006-10-04 08:25:56 PDT
Message > Why get an instance of each object?

Why? Because re-using objects is:

1. BAD OO design... one instance == 1 LOGICAL instance. If you re-use
it, you are pretty much breaking black-box. "Clients" of your objects
don't expect this behavior, because it's bad OO design.

What if in the course of using FETCH_INTO, you have some relationships:

foreach (FETCH_INTO loop) {
    $myObj->setRelat​edObject($Y);
}

Well this is going to end up an awful mess, with no referential
integrity in your object model.

2. There is no meaningful benefit to FETCH_INTO. Seriously, name one
potential benefit of doing this. Are you thinking performance? Lots
of things in OO would be faster if you break the OO... but it
shouldn't be done.

3. With your example:

> Now, i wanna publish a List of Person with their fullnames. I don`t
> want to
> change data or something -> just want to print table containting the
> fullname and some columns additional information. I`ll implement a
> method
> getFullname in my Object-Class:

Ok great! That's a completely reasonable thing to want to do.
HOWEVER, I don't see why getting back DISTINCT instances for each
iteration prevents this from happening. It doesn't use more memory
and it isn't much slower (only real speed difference is calling the
constructor).

However, I can promise you that getting back the SAME instance each
time, but it having different data for *some* columns, will
definitely cause you hours of painful debugging, followed by "Why am
I using FETCH_INTO"?

---------

Just b/c PHP does something, doesn't mean that it's a good idea, or
that every project using it should "wrap" that functionality.

I'd be happy to continue this conversation, IFF you can provide an
example of something that FETCH_INTO provides that you can't
otherwise do.

Alan