On Wed, Feb 20, 2008 at 1:38 AM, Robert Cummings <[EMAIL PROTECTED]>
wrote:

> Actually, using foreach on an array has less overhead than an iterator
> on an object.


yes they are; see my experiment results here,
http://nathan.moxune.com/arrayVsArrayIteratorReport.php

and i hear what youre saying rob; at least i think so, namely, why
try to build in a set of operations into the group class for every single
possibility, even though they are centralized, you wouldnt want the
developer of the group class having to write a new method every
time one of the clients wanted something new; thats just madness.
and frankly impractical, because we all know how these release cycles
can be :)
anyway, there are plenty of options for the group class. 2 come to
mind immediately, the first allows you to apply a callback to every
element of the group; this is something like you would see in a functional
language, but it works pretty well w/ the php callback pseudo type as
well.  and in fact, spl is incorporating this in 5.3, according to marcus.
the next option is to subclass the group object for your particular
operation.
then you could have a number of specialized child classes, that each,
are, the parent class and exhibit the specialized functionality.  and the
best part is, the group class writer gets to chill in both scenarios :D

nick is right to an extent; reproducing the same client code in multiple
places is not good.  however, rob is right too; you cant think of every
conceivable operation and build it into the group class.  fortunately we
have callbacks and inheritance; and there are other elegant solutions
as well, just that none pop into my head in under a second :)

my thought is that *sometimes* returning an array is appropriate, and
*sometimes* returning an object is appropriate.  it depends upon the
scenario; this is such a generic, common issue that you cant say one
is better than the other in all cases, because frankly neither is better
in all cases.

-nathan

Reply via email to