to each his own; i am somewhat of an oop zealot, but i will advise u to heed
the reality that php affords the use of functions in the global namespace
and this feature is often useful even if an application is oop-centric.
sometimes being able to just crank out a function and be done w/ it is nice
:) and other times it makes sense from a design perspective to offer
'convenience' functions in the global scope, which often times may actually
dip into functionality implemented in a class. this sort of stuff will be
getting a twist in days to come (php 5.3+) when we will be able to write
functions (that arent class members) and segregate them from the global
scope albiet namespaces.
-nathan
Everything, yes. Sometimes all you need is a quick and not so dirty
function. Though saying that, OO is generally thought of as the way to go.
> 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.
Based on what you've described I would go with the following classes:
Movie
This class would handle fetching the movies data, updating it and/or
deleting it. Or you could have a static Movie method for deleting one,
eg Movie::Delete($id). Could also have a static Add() method which
creates a movie and returns a movie object.
DB Connection
There are plenty of database classes around (not least my own PEAR
replica - http://www.phpguru.org/article.php/121). Others include MDB2,
PDO, ADODB etc.
Movie Listing(s) (abstract?)
|
+- By name (alphabetical
+- By category
+- By keyword
+- By date (chronological)
Here you'd have the code to show listings. With common code on the
parent movie listings class and with specific code on the appropriate
child class.
--
Richard Heyes
Employ me:
http://www.phpguru.org/cv
-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
la...@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