[Zope3-dev] Context and Component Lookup

Martijn Faassen faassen at vet.uu.nl
Thu Aug 7 18:11:09 EDT 2003


Jim Fulton wrote:
> >And that makes it clearer that we aren't quite on the same page.  My 
> >point was that if the "foreign" component does a utility lookup on 
> >itself, and gets a different result based on who called it, that this 
> >isn't a good idea. 
> 
> Right, I understand your point.  My point is that it shouldn't matter
> because the interactions are through a common interface.

That doesn't make sense to me. I can have two views, A and B, which
have the same interface and are associated with the same content
object interface. But it certainly matters which view is shown.

What if I have two interfaces that do some storage, one using a relational 
backend and the other the ZODB? Exact same interfaces but I certainly don't
want to switch from one to the other just like that.

Interfaces make code more flexible and it makes it more easy to
plug in interchangeably, but it doesn't mean that the implementation
doesn't matter, otherwise you'd only ever need a single implementation
of an interface...

[snip]
> Oh come on. Encapsulation is provided through interfaces.  If a component
> claims to depend on an interface, but isn't willing to accept alternate
> components that implement the interface, then *there* is the encapsulation
> problem.  When we use the component architecture, it's because we *want*
> to be used with alternative components. All we depend on is the interface.

But if using an alternate component means I need to *know* which components
are going to be looked up by that alternate component so I can actually
supply them in my context, then *that* breaks encapsulation. I shouldn't
have to know which components are looked up by another component in
order to use it. It's specified nowhere in the interface. Are you saying
this should be specified in the interface? 

> For example, utilities are a lot like modules, except that they can be
> substituted. They are a means of indirection. If I really need a particular
> component, I should get it by some other means that component lookup.
> 
> Having said that, I now understand and accept that you want an intermediate
> level of indirection, where you'll be willing to accept any component that
> implements the specified interface *and* comes from a particular source.
> 
> In general, I suggest that components don't and shouldn't care what
> other components they get hooked up to as long as those components satisfy
> their contracts.

What if there's a data dependency? A service may maintain state about
particular objects, if only a cache, right?

Regards,

Martijn




More information about the Zope3-dev mailing list