benifactor wrote:
ok, about five minutes ago i decided to learn classes and delve into php's oop side.
what i came up with was this...
//start example code
class newsletter {
function send ($email,$subject,$message) {
if ($email) {
echo("the following message was sent to: $email <br> subject: $subject<br><br> $message");
}
else {
echo("failure");
}
}
}
$new = new newsletter();
$new->send("test@xxxxxxxxx", "test class", "test class worked, i have passed and failed the test.");
//end code example
..and this seems to work fine, i could easily add the mail function and insert real variables into send() but what i don't understand is i could also easily do this without a class... so i guess the real question is what are some real life examples of class usage and why is it used as opposed to regular non oop? thank you for any input into the subject that you may have.
Pick up a general book on OOA/D development. IMHO, the advantage of OO
is to modularize your code with encapsulation(buzz word). Basically
meaning that as long as your interface to an object does not change, it
does not matter to the *outside world* what you do behind the scenes.
This is especially beneficial for abstracting layers (as someone else
pointed out with the DB abstraction), as well as working within teams of
developers.
Done right it enhances all the *ilities* of software development, done
wrong it is a horrific mess of spaghetti!
Another advantage could be design *might* be easier because UML exists
as a nicely featured modeling language which maps very nicely to classes
in OO.
When all is said and done it is another tool in software development.
It has its purposes and when wielded by persons who know how best to use
it, it is quite a good method. But be your own judge, and read some
about it!
Another *real world* example might be taking the DB abstraction a little
further.
Represent all your tables as classes. This gives you the ability to
properly scrub, validate data before assigning it, allows you to
automatically persist the data (if you choose) when the class goes out
of scope, gives easy access of data to people who need not concern
themselves with the DB schema, etc..
Really a nice tool for this case, especially when you inherit a schema
which is less the obvious ;-)
-B
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php