base class
Posted: Wed Oct 01, 2008 4:37 pm
I know some would like to shoot me based on the title alone
I've seen frameworks where about every object gets passed an instance of a service locator or registry or something with similar capabilities. This in the name of avoiding globals, which, we all know, are bad. I think passing this introduces a new kind of global object though. And worse, often you can't even be sure what object class you get when you ask this service locator for an object (eg database) other than you happened to read the bootstrap file.
Based on this observation I think it can't be that bad to have a base class having methods that locates a service. Or provides access to a logger object so you can do '$this->log('start_authentication_check')'. What would be against having these two kinds of functionality in a base class as opposed to the situation described above?
I've seen frameworks where about every object gets passed an instance of a service locator or registry or something with similar capabilities. This in the name of avoiding globals, which, we all know, are bad. I think passing this introduces a new kind of global object though. And worse, often you can't even be sure what object class you get when you ask this service locator for an object (eg database) other than you happened to read the bootstrap file.
Based on this observation I think it can't be that bad to have a base class having methods that locates a service. Or provides access to a logger object so you can do '$this->log('start_authentication_check')'. What would be against having these two kinds of functionality in a base class as opposed to the situation described above?