On Tue, Mar 15, 2011 at 4:12 AM, Gavin Panella
<email address hidden> wrote:
>> > if IOneInterface.providedBy(an_argument):
>> > do_something()
>> > elif IOtherInterface.providedBy(an_argument):
>> > do_something_else()
>>
>> I share that dislike, but I don't see how that applies to this context.
>
> If I don't use adapters but want to keep the ability to work in a
> distribution or distroseries context I can't really see a way around
> the IFoo.providedBy(...) stuff.
>
> Well, I could getattr(context, "distribution", context) but I suspect that
> might an order of magnitude worse again :)
There are a few general patterns that can be used here:
- delegation:
an_argument.do_something() -> trust it will dtrt.
an_argument can have a range of techniques to have do_something
implemented appropropriately.
- multiple dispatch: register (in advance) how you want to dispatch
things, and then dispatch off a tuple of types rather than just the
type of an_argument:
do_something(an_argument, self) -> will handle the type consideration for you
- adaption - a primitive form of multiple dispatch - cast or acquire
into a known type and then call a method on it:
IPillar(an_argument).do_something
- case statements: the thing we all dislike :)
adaption makes me nervous unless there is /clearly/ and /forevermore/
One Sensible Answer : and distroseries -> distribution violates the
second condition: for a derived distribution, there are multiple
reasonable answers to 'I need a distribution for this distroseries' -
there is .distribution, and there is .parent_series.distribution.
Generally speaking, I reach for delegation as the first tool to hand
in these sorts of situations, though it may not be the right tool for
this specific situation.
On Tue, Mar 15, 2011 at 4:12 AM, Gavin Panella providedBy( an_argument) : .providedBy( an_argument) : (...) stuff.
<email address hidden> wrote:
>> > if IOneInterface.
>> > do_something()
>> > elif IOtherInterface
>> > do_something_else()
>>
>> I share that dislike, but I don't see how that applies to this context.
>
> If I don't use adapters but want to keep the ability to work in a
> distribution or distroseries context I can't really see a way around
> the IFoo.providedBy
>
> Well, I could getattr(context, "distribution", context) but I suspect that
> might an order of magnitude worse again :)
There are a few general patterns that can be used here: do_something( ) -> trust it will dtrt. (an_argument, self) -> will handle the type consideration for you an_argument) .do_something
- delegation:
an_argument.
an_argument can have a range of techniques to have do_something
implemented appropropriately.
- multiple dispatch: register (in advance) how you want to dispatch
things, and then dispatch off a tuple of types rather than just the
type of an_argument:
do_something
- adaption - a primitive form of multiple dispatch - cast or acquire
into a known type and then call a method on it:
IPillar(
- case statements: the thing we all dislike :)
adaption makes me nervous unless there is /clearly/ and /forevermore/ series. distribution.
One Sensible Answer : and distroseries -> distribution violates the
second condition: for a derived distribution, there are multiple
reasonable answers to 'I need a distribution for this distroseries' -
there is .distribution, and there is .parent_
Generally speaking, I reach for delegation as the first tool to hand
in these sorts of situations, though it may not be the right tool for
this specific situation.
HTH,
Rob