Posted: Thu Nov 04, 2004 3:50 pm
I've been thinking about this for some time now, and although your approach makes sense, I feel that fact of your first class "relying" on two other classes seems to somewhat defeat (Or at least try to circumvent) the entire point of OOP.timvw wrote:for my Database Table class I ended up with following methods:
- create // accepts array with key=value pairs
- read // accepts sql where clause, offset and limit
- update // accepts array with key=value pairs (need the primary key)
- delete // accepts array with key=value pairs (need the primary key)
then i also have:
- getDataDictionary // returns a hash with the fields in the db table
- getValidator // returns an instance of a class that does validation
- getFormatter // returns an instance of a class that does formatting
validator has methods:
- validate_create
- validate_read
- validate_update
- validate_delete
formatter has methods:
- pre_create
- post_create
- pre_read
- post_read
- pre_update
- post_update
- pre_delete
- post_delete
What I feel is needed (for my project) is an Query class that can stand on its own. When it comes to validating / formatting data, you could always have the Validator / Formatter class "extend" the Database Table class, but this then leaves the Database Table class as somewhat useless.
The approach I am taking is to have the Query, Validator, and Formatter classes completely seperate from each other. When I need to format some data to prepare it to be queried, I would run it like such:
Code: Select all
<?PHP
$query = new Query();
$format = new Format();
$formatted_data = $format->create($data);
$query->create($formatted_data);
?>Any thoughts?
- Monkey