I think you're also in need of message passing. The act of an object passing a message to another object.
As an example, if you consider that a collection of objects all do some slightly different things, it may be needful for these objects to communicate. There are two methods that I know of. One of them is mostly just an idea that I'm working on and less than suitable for a web environment.
1) The first method is to make an object aware of other objects that can fulfill a need for it. This introduces some coupling, but in this case it's good.
2) The idea I have is to create an interrogation mechanism so objects can
find other objects that can provide them a service.
The first one is far more feasible at this point so we'll continue with it.
To go on, I have an object for storing sessions in a db. However that object doesn't do any of it's own work against the db. It has another object do it via a command like this:
So my sessions object has registered to it a query object of which it knows the interface. The query object provides the service that the sessions object needs. How sweet.
Now that we're feeling warm and fuzzy, I would suggest you do something similar for your validation
AND error class. To accomplish this, you need to:
Code: Select all
// Pass the error or validation object to let's say your'e db object.
$db_object->setErrorHandler(&$error_object);
Notice the '&'? Won't work otherwise until PHP5.

Also, you're not forced to use a set() type method. I pass it in the constructor, even though it's less flexible. Another option is to just do...
Code: Select all
$db_object->errorHandler=&$errorObject;
...which drives the zealots crazy! But who am I to care?
Then somewhere in your db class, just dump errors to the error class when an error occurs.
Code: Select all
if($this->doQuery()==false)
{ $this->errorHandler->logError($this->mysql_error()); }
$this->errorHandler being a reference to your errorHandler object.
I hope this helps.
Cheers,
BDKR