RE: [PEAR-DEV] general questions
| From: | Richard Heyes | Date: | Thu, 29 Nov 2001 01:10:42 +0000 |
| Subject: | RE: [PEAR-DEV] general questions | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-3172@lists.php.net to get a copy of this message | ||
> > > > > > But why do stuff like DB::connect ?
> > > > > > Why not put stuff like that in a constructor?
> > > > >
> > > > > Because DB::connect() can return you a correct object type (ie
> > > mysql/pgsql).
> > > >
> > Well an object can do this also. You just require the proper code in the
> > constructor ... Ulf called this a factory in his speech at the php
> > conference iirc
>
> True, but you need an object first. What's the point in creating an object
> just to get another object?
I phrased that wrong. A constructor does not return a value. So to return an
appropriate object you would need to create an object, and then call one of
its' methods. This is pointless to create an object just to get another type
of object.
> I guess you are right ... so a factory is not supposed to reside in side
> the class it is "producing" for? Why?
If it's in the object you want, then there's no point, you might as well
just create the object you want. If it's in DB::, then it can work out which
object to create from the data you pass it.
--
Richard Heyes
"If you have any trouble sounding condescending,
find a Unix user to show you how it's done." - Scott Adams