|
Posted by Kenneth Downs on 05/10/05 00:22
bissatch@yahoo.co.uk wrote:
> Hi,
>
> Generally if I re-use code, I use a function. If I need to use these
> functions over a number of pages I write the function to an include
> file where all pages have access.
>
> So when should I ever use PHP classes instead. I have learned how to
> put together PHP classes but never seen a reason to use them where I
> can simply use a function.
>
> Im basically just wanting to know classes benefits over functions. If
> something can be better put together in a class I would like to be
> doing it that way. Any suggestions?
>
This is a matter of opinion. One extreme states the fact that classes give
you nothing you can't have without them, and says why bother and does not
use them at all. The other extreme can't code "Hello, World!" without 5
layers of inheritance and a dozen composite objects.
So the real question is, what jobs are they good for? Also, what kind of
site are you building? Is there something you are having trouble doing?
In our system we write database applications, we use a dispatcher and
functions, plus a scheme for storing lots of config parms in
ready-to-execute include files that populate associative arrays. This
takes care of 99% of cases.
The only place where I have found it actually easier to use a class is for
providing overrides to default behavior. The one single class we have
contains some very basic behaviors, and contains calls at different points
to empty class methods. If I need to override default behavior, I make up
a class for that page (normally I don't need a class for most pages, the
libraries know what to do), and code up one or two of those trigger methods
to nudge processing in one direction or another.
But as for making one-class-per-table, yuck.
--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)
Navigation:
[Reply to this message]
|