Re: PHP5 and the DOM model

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Apr 17, 2008 at 5:43 PM, Nick Stinemates <nick@xxxxxxxxxxxxxx>
wrote:

> On Thu, Apr 17, 2008 at 10:05:11AM +0200, Michael Preminger wrote:
> > Hello!
> >
> > Seems that PHP gets more and more object oriented, which is good.
> >
> > I am now running a course in PHP, using PHP 5, where we are going to
> > use the *DOM* interface. I am trying to teach them good OO practices,
> > meaning that we insistently hide properties and expose them as get or
> > set methods.
>
> Get/set methods are more often than not breaking encapsulation and
> should be avoided (unless purposefully designing Model object or
> something similar.)
>

egh?  we had a massive argument about this last year, but if u ask me data
hiding is an integral part of encapsulation; therefore i agree w/ Michael.

>
> Looking at the PHPs *DOM* implementation, I see that many of the
> properties are exposed directly, without even offering get methods.

so, if its a big deal, write a proxy(s) which adds the encapsulation (as u
see it) u need.

Can you please provide an example of where this is happening?
>

heres a list of em from DomDocument,
readonly public string
$actualEncoding<http://us2.php.net/manual/en/class.domdocument.php#domdocument.props.actualencoding>;
 readonly public DOMConfiguration
$config<http://us2.php.net/manual/en/class.domdocument.php#domdocument.props.config>;
 readonly public
DOMDocumentType<http://us2.php.net/manual/en/class.domdocumenttype.php>
$doctype<http://us2.php.net/manual/en/class.domdocument.php#domdocument.props.doctype>;
 readonly public DOMElement<http://us2.php.net/manual/en/class.domelement.php>
$documentElement<http://us2.php.net/manual/en/class.domdocument.php#domdocument.props.documentelement>;
 public string $documentURI<http://us2.php.net/manual/en/class.domdocument.php#domdocument.props.documenturi>;
 public string $encoding<http://us2.php.net/manual/en/class.domdocument.php#domdocument.props.encoding>;
 public bool $formatOutput<http://us2.php.net/manual/en/class.domdocument.php#domdocument.props.formatoutput>;
 readonly public
DOMImplementation<http://us2.php.net/manual/en/class.domimplementation.php>
$implementation<http://us2.php.net/manual/en/class.domdocument.php#domdocument.props.implementation>;
 public bool $preserveWhiteSpace<http://us2.php.net/manual/en/class.domdocument.php#domdocument.props.preservewhitespace>
=true ;
 public bool $recover<http://us2.php.net/manual/en/class.domdocument.php#domdocument.props.recover>;
 public bool $resolveExternals<http://us2.php.net/manual/en/class.domdocument.php#domdocument.props.resolveexternals>;
 public bool $standalone<http://us2.php.net/manual/en/class.domdocument.php#domdocument.props.standalone>;
 public bool $strictErrorChecking<http://us2.php.net/manual/en/class.domdocument.php#domdocument.props.stricterrorchecking>
=true ;
 public bool $substituteEntities<http://us2.php.net/manual/en/class.domdocument.php#domdocument.props.substituteentities>;
 public bool $validateOnParse<http://us2.php.net/manual/en/class.domdocument.php#domdocument.props.validateonparse>
=false ;
 public string $version<http://us2.php.net/manual/en/class.domdocument.php#domdocument.props.version>;
 readonly public string
$xmlEncoding<http://us2.php.net/manual/en/class.domdocument.php#domdocument.props.xmlencoding>;
 public bool $xmlStandalone<http://us2.php.net/manual/en/class.domdocument.php#domdocument.props.xmlstandalone>;
 public string $xmlVersion<http://us2.php.net/manual/en/class.domdocument.php#domdocument.props.xmlversion>;

>
> 1. Is there something I am misunderstanding orotherwise missing? (I
> havenot used *DOM* in PHP before).

have you looked at SimpleXMLElement / SimpleXMLIterator ??  i find it to be
one of those 80% / 20% relationships where simplexml takes care of the needs
most of the time (and saves your poor brain from smoking).

> 2.This poses a pedagogical problem for me as a teacher. How do I
> explain this contradiction to my students?

the world doest operate 'by-the-book'  thats life.  i was a teacher once
(just for a semester) but i was teaching oop.  at the end of the day who
knows why they did it that way.  perhaps their views are different than
yours or the book from which your teaching.  explain to them that there are
options, such as building a proxy, but there will be consequences in terms
of performance and increased complexity.

-nathan

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux