← Back to team overview

launchpad-dev team mailing list archive

Re: Adapters & API (was Re: Exposing newCodeImport)

 

On Mon, 29 Mar 2010 14:59:12 -0400, Leonard Richardson <leonard.richardson@xxxxxxxxxxxxx> wrote:
> 
> > >> > IBranchTarget has several implementations, one for each of product,
> > >> > sourcepackage, person, and productseries. I want the method to be only
> > >> > available on the first two if possible, but it's fine if it has to be
> > >> > all four, as it is part of the interface after all.
> 
> Assuming I understand what you're trying to do, the simplest way to
> represent this would be to define an annotation like
> @import_from_adapter() and put @import_from_adapter(IBranchTarget) in
> IProduct and ISourcePackage, while leaving it out of IPerson and
> IProductSeries.
> 
> In IBranchTarget you would have an annotation like
> @only_used_in_adaptations that would stop it from being exported as a
> separate entry type. You would publish IBranchTarget.name as
> "branch_target_name" (or whatever you wanted) to avoid colliding with a
> 'name' declared in IProduct or ISourcePackage. The same would hold true
> for IBranchTargetName's named operations. You can choose whatever name
> you want, but if that name conflicts with a name found in the original
> interface, the original interface takes precedence.
> 
> The end result would be 'product' and 'source_package' looking like they
> had everything that's @exported in IBranchTarget. Behind the scenes, a
> product or source package would be adapted to IBranchTarget to retrieve
> values like 'branch_target_name'. A PATCH that modified (eg.) both name
> and branch_target_name would make both object modifications within a
> single database transaction.
> 
> Would this work? (This is not something I can get to anytime soon, BTW.)

That sounds like it would work fine for me.

It's clearly more work than a small mixin, so is it worth the effort to
do this? Are there other adapters that we may want to expose? Is it a
pattern that will grow in usage in the LP codebase?

Thanks,

James



References