Re: everything as classes
| From: | Larry Garfield | Date: | Sat, 05 Apr 2008 13:36:43 +0000 |
| Subject: | Re: everything as classes | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-272566@lists.php.net to get a copy of this message | ||
On Thursday 03 April 2008, robert wrote:
> Along the lines of a previous post "How to get a code review", I am
> curious if it is overkill to create everything in classes. For
> example, a movie website where there is a class for the movie
> datatype, class for getting/adding/deleting/updating movie's data to
> the database, and class for displaying the data. (Of course there are
> classes for general functionality like sql database connection etc.)
> For listing movies alone there are at least 4 different inheritance
> classes for chronological, alphabetic, category and keyword. Anyway
> this is how I coded something similar but for Flash/Actionscript site
> but I'm not sure about a PHP site. I appreciate your comments.
> - robert
Procedural code is a hack saw.
OOP is a table saw.
Sometimes, all you need is a hack saw. It's simple, straightforward, easy to
learn how to use, and you can pick it up and use it in various ways and
places. It's harder to get wrong, and when you do you can usually just turn
your hand at a weird angle for a bit and make it work.
Other times, you really need a table saw. It takes longer to build and setup
and can be more difficult to understand if you're not used to it, but if done
properly will slice and dice wood in ways you couldn't even think of with a
hack saw. Of course, if you build it wrong then you're now out a very
expensive table.
Use whichever makes sense for your use case. In a language like PHP that has
strong support for both, both the "everything is an object" and "never use
objects" viewpoints are, well, ignorant. :-)
--
Larry Garfield AIM: LOLG42
larry@garfieldtech.com ICQ: 6817012
"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson