|
Posted by farrishj@gmail.com on 05/28/07 21:32
On May 28, 4:28 pm, "farri...@gmail.com" <farri...@gmail.com> wrote:
> On May 28, 3:44 pm, "Gregor" <rmba...@comcast.net> wrote:
>
> > This is partially an opinion question. I have some modularization for my
> > main site using vanilla PHP. I'm a one-man operation.
>
> > Is there any major benefit to learning and using OOP? I have lots of other
> > stuff to be spending my limited intelligence learning.
>
> OOP is VERY useful for one-man operations. Learning OOP, however, is
> somewhat time-consuming (which is not good for one-man ops).
>
> If you're in PHP 5, you're a lot better off OOP-wise. This makes it a
> little difficult, if you learn PHP5 and use it's OOP features, but
> then somehow get stuck in PHP 4, which is a lot more free-wheeling
> (think JavaScript).
>
> This is a really difficult question to answer, since bad OOP-
> influenced code can be WORSE than some procedural or functional code.
> But it sure makes it a lot less finger-breaking to code:
>
> <code>
> class Build_Html_Page {
> public static function __construct($key) {
> $str = $this->getHtmlHeader() .
> $this->getHtmlBody($key) .
> $this->getHtmlFooter();
> return $str;
> }
> protected function getHtmlHeader() {
> include BASE_PATH.'/INC/html-head.inc.php';
> }
> protected function getHtmlFooter() {
> include BASE_PATH.'/INC/html-foot.inc.php';
> }
> protected function getHtmlBody() {
> include BASE_PATH.'/INC/switch_content'.
> $this->getSwitchKey().
> '.inc.php';
> }
> protected function getSwitchKey() {
> $key = empty($_GET['section']) === true ?
> 'index' : $_GET['section'];
> return $key;
> }}
>
> $site = new Build_Html_Page();
> echo($site);
> </code>
>
> There you have a very low-key front-controller for a website. If you
> want to change the switch section key logic, it sits in one place, and
> one place only.
>
> I personally like:
>
> http://www.seagullproject.org
>
> Also, try the Google Maps API to see a professionally-developed OOP
> script (in JavaScript). Once you use objects well-developed, it makes
> all the difference.
Also, Harry Fuecks over at sitepoint.com has some really good books on
PHP OOP.
If you want to learn to code using OOP techniques, you also MUST learn
about design patterns:
http://en.wikipedia.org/wiki/Design_pattern_(computer_science)
[Back to original message]
|