Re: everything as classes

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

 



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.

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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[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