[Solar-talk] Proposal: Remove namespace to Solar::loadClass()/factory()
Travis Swicegood
development at domain51.com
Tue Nov 7 09:37:25 PST 2006
Hi Antti,
Antti Holvikari wrote:
> On 11/7/06, Travis Swicegood <development at domain51.com> wrote:
>
>> Howdy all,
>>
>> One thing in Solar that's been bugging me is the concrete class
>> dependencies that it has. Code like this makes me cringe:
>>
>> $sql = Solar::factory('Solar_Sql');
>>
>> My whole problem with it is that it creates a dependency on Solar_Sql
>> and keeps me to inserting my own Domain51_Sql code. My solution, as
>> Paul has heard many (he would add "many, many" I believe) times is some
>> sort of Dependency Injection model where you don't request the class,
>> but it's interface.
>>
> Sorry if I have completely missed your point but doesn't
> Solar::dependency() do the job?
>
Yes and no. dependency() serves a similar purpose, but is different in
that you must specify what you want to get back. Generally that's done
via config, so it is configurable, but what I am suggesting is that you
request "Sql" and get back the first matching object in a vendor's
namespace called "Sql".
So, assuming Solar is the only registered namespace:
$sql = Solar::factory('Sql');
// $sql instance of Solar_Sql
-Travis
More information about the solar-talk
mailing list