You are here: Re: To OOP or not to OOP « PHP Programming Language « IT news, forums, messages
Re: To OOP or not to OOP

Posted by farrishj@gmail.com on 05/28/07 21:28

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.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация