Re: class usage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2006/9/29, benifactor <snorris17@xxxxxxx>:

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


Why does your newsletter class have mailing logic?
Is your newsletter an abstraction of a newsletter or an abstraction of a
mailing system?
I would expect from a newsletter object the following:
* A way to indicate the format of the newsletter (plain text/html)
* That it asks me for the newsletter template
* A way to provide it with specific client data to create the newsletter for
that client
* A common interface to interact with mailing system abstraction (to send
the newsletter)

IMHO: this is not OOP, objects ARE NOT function repositories.

..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.


Whatever you do in OOP could have been easily done without. OOP doesn't add
anything in terms of functionality, on the contrary, OOP takes away your
freedom to do many things you can do without it, but that's the whole point
of it: the coder putting contraints on himself or other coders so that we
don't mess up.

But having only that is not real OOP. Real OOP is reusability on steroids.
If you code thinking how your objects could be used for something more that
what you're doing right now, you'll have your current problem solved and
future problems will be easier to solve.

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux