[thelist] php design question

Andrew Forsberg andrew at thepander.co.nz
Mon Nov 18 19:53:01 CST 2002


hi rudy

> the martini example made me thirsty, but brought zero additional
> understanding to my pathetic levels of comprehension
>

my bad.

>
> nobody has said boo yet about how objects are better than includes
>

they're not better or worse -- they're different. in php (at least)
classes are normally included via require_once() or include_once()
anyway.

here's my second attempt:

say the original poster in this thread decided to rewrite his app to
use objects instead of includes. in that case he might create a class
called Menu, then include this class in his program, then every time he
wanted to create a menu he'd make a new menu object:

require_once('../incs/Menu.php');
$menu = new menu();

then, say we wanted to add a new listing to the menu:

$menu->addOption("stir the cocktail", "/index.php?go=stir");

or, delete an option:

$menu->deleteOption("quit");

or, change the colour of the menu bar:

$menu->changeColor("go BLUE!!!");

finally, to output the menu one might:

$menu->printMenu();

so, the idea is to restrict all the menu related stuff to the menu
object. all the formatting, sql, output, etc go are called from the
menu object itself. other things don't get to muck with how the menu
object changes background colour, they just ask the menu object to do
it.

the point? well, if the db driving the menu system changes then we just
need to alter the menu class; if we want a breadcrumb trail, we can
extend the menu system and change the way it formats itself -- the same
info is required, afterall.


> where were we?  oh yeah, includes

still important, not usurped, don't fear. :|


hope this wasn't as muddled sounding.




More information about the thelist mailing list