[Zope3-dev] factoryFromClass: for_container

Gary Poster Gary Poster" <garyposter@earthlink.net
Tue, 16 Apr 2002 14:53:33 -0400


From: "Lalo Martins" <lalo@laranja.org>
> On Mon, Apr 15, 2002 at 02:34:14PM -0400, Jim Fulton wrote:
> >
> > BTW, another way to approach this is to have containers say which kinds
of
> > things they are willing to contain, by specifying an interface that
their items
> > must support. Maybe this is related to what you are proposing.
>
> These two things are complementar.

Yes--but see the zwiki page where I discuss this more, and see below.

> Having a factory zcml is good because you can make new types available in
> existing containers and existing types available in new containers. This
> makes the set broader.
>
> Being able to filter by interface is also interesting, because it makes
the
> set narrower.
>
> Or in other words:
>
> If we only had interface filters, it would be a pain to create a new class
> and declare that it can be added to JobBoards.
>
> If we only had Gary's way, then a Job object could only be created in a
> JobBoard, but the JobBoard add list would have Job *and* all other things
> IContainer has.

Actually not true: JobBoard is not an IContainer.  In this instance,
for_container would do the job in both directions.  I think it would do the
job in all cases that did not require special individual folder adder views
anyway.

Another clarification: both methods are by interface.  for_container is an
object specifying what container interface to which it can be added.  Jim's
approach is for an object to specify what interfaces it can hold.  So the
two approaches are even more complimentary, in that sense.  They are really
exact mirrors.

> So I think if the goal is to mimic (or beat!) the factory flexibility in
Z2,
> then we need both.

I don't agree, but I could be wrong, and I'm willing to go along (and
implement) if I'm outvoted.  Again, I give more in the wiki page that Jim
requested I put up.  Please glance there, consider my further arguments, and
make further comments there.

http://dev.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/FactoryFrom
ClassChanges

I do think that eventually we may want folders that can *individually* (per
instance) specify what can be contained in them, perhaps, (if LoadedFolder
doesn't do that already) but that is a different ball of wax from
registering classes as factories, which is what we're talking about here.

Gary