Stephen Craton said:
> I used OO in my chat script (can be found at
> http://php.melchior.us) but it really seemed like a waste
> since it was such a small basic script. I never
> really find myself re-needing code except for database
> connectivity and calling the database and stuff like that.

My boss, before he really understood OOP, would take ordinary proceedural
code and wrap it in a class, which still wasn't object-oriented.  I fear
you've done the same in your code (even though I haven't seen it) and are
wondering what the big whoop is about.  I believe that if you don't
understand OO, you haven't been using OO.

Once you understand the whys (after using it for a bit) you'll see why
it's so cool.  Now I wanna code everything OO :-)

I really understood it when a Java programmer I know once said "In
proceedural code, the nuts-and-bolts are functions which are verbs
(get_data(), open_database(), write_file()) while in object-oriented code,
the nuts and bolts are objects which are nouns ($user, $group, $job,
$house)."

So I'd build an OO chat room like so (pseudocode):
class chatroom
 values: private or public, admin, name, max_users, comments, admin_present
 methods: get/set_public_or_private, get/set_admin, get/set_name,
get/set_max_users, get/set_comments, display_help, update_member_list,
get/set_admin_present
class user
 values: permission level, name, email address, password
 methods: get/set permission level, get/set name, get/set email_address,
get/set password, join_chat_room, create_chat_room, leave_chat_room
class system chatroom extends chatroom
 methods: check permissions, restart server

$phpchat = new chatroom ("phpchat");
$phpchat->set_public_or_private ("public");
$phpchat->set_admin ("[EMAIL PROTECTED]");
$phpchat->set_comments ("A great place to talk about PHP");

$user-> new user ("[EMAIL PROTECTED]");
$user->join_chat_root ("phpchat");
if ($phpchat->get_admin() == $user->get_email_address()) {
$phpchat->set_admin_present(TRUE); }
$phpchat->update_member_list();
...

It's not perfect but hopefully you'll understand the magic.
/dev/idal

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

Reply via email to