On Fri, 2004-01-30 at 04:41, Chris Neale wrote:
> The main application would then do this:
> 
> $q = new dbObj;
> $x = new iterator;
> $y = new HTMLGenerator($q, $x)
> 
> while ($x->next())
> {
>       $y->MakeHTML();
>       $y->outputToFile();
> }
> 
> Anyone got any thoughts about whether this is a good way to do it? I was 
> wondering whether instantiating objects should be done within other objects 
> that need them - if this can be done - but I would only do that in cases 
> where (for instance) an HTMLGenerator object is instantiated without any 
> parameters, in which case some logic could be added to do this.

Others have already commented on the OO structure and I agree that this
approach looks sound.  I do have a comment about the code you
illustrated.  I noticed you are passing the iterator to the
HTMLGenerator on instantiation, then afterwords processing through the
iterator and calling methods on the HTMLGenerator.  Since the
HTMLGenerator has a copy of the iterator it could theoretically do this
itself.  For example:

$q = new dbObj;
$x = new iterator;
$y = new HTMLGenerator($q)

$y->processIterator($x);

And then create the processIterator method like so:

HTMLGenerator::processIterator($iterator) {
        while ($data = $iterator->next()) {
                $this->MakeHTML($data);
                $this->outputToFile();
        }
}

This will logically allow you to do more things with your HTMLGenerator
(like generate HTML that is not tied to the iterator) as well as use
different iterators in the same HTMLGenerator instance, etc.  Also, if
the iterator is what is using the dbObj class (to iterate through the
database data) then consider passing it to the iterator instead.

Regards,
Adam

-- 
Adam Bregenzer
[EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to