[Baypiggies] Are there any good examples of implementing dependency inversion in Python?

Mahmoud Hashemi mahmoud at hatnote.com
Sun Feb 26 19:04:07 EST 2017


It was my impression that inversion and injection were really closely
related, based on various Fowler talks, including this canonical essay:
https://martinfowler.com/articles/injection.html

My main takeaway has always been, pass the low-level implementation _into_
the higher level construct, instead of expecting the higher-level wrapper
to create it for you. This is especially visible in Twisted's
Protocol-based approach, now visible in asyncio, and more broadly all the
sans-io libraries: http://sans-io.readthedocs.io/

For a very basic example, consider this JSONLines (jsonlines.org) iterator:
http://boltons.readthedocs.io/en/latest/jsonutils.html

Rather than doing JSONLIterator('target.jsonl') directly, one would do
JSONLIterator(open('target.jsonl')), passing in the open file object (or
any file-like object). Hope that makes sense!

Mahmoud



On Sun, Feb 26, 2017 at 3:54 PM, Alex Martelli via Baypiggies <
baypiggies at python.org> wrote:

> I see you're getting answers on dependency *injection* (on which I would
> suggest my talk, slides at http://www.aleax.it/yt_pydi.pdf --
> unfortunately I don't know of a video recording of said talk) while you
> asked about dependency *inversion* (related, but definitely not the same
> thing), for which I don't know of much that's published apart from what a
> search will easily find, such as https://www.lynda.com/
> Programming-Languages-tutorials/Introduction-dependency-inversion/471978/
> 502206-4.html .
>
> Alex
>
> On Sun, Feb 26, 2017 at 12:55 PM, Braun Brelin <bbrelin at gmail.com> wrote:
>
>> Hi,
>>
>> Looking for some good examples of Dependency Inversion in Python.  Anyone
>> have any suggestions for sites to look at?
>>
>> Thanks,
>>
>> _______________________________________________
>> Baypiggies mailing list
>> Baypiggies at python.org
>> To change your subscription options or unsubscribe:
>> https://mail.python.org/mailman/listinfo/baypiggies
>>
>
>
> _______________________________________________
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
> https://mail.python.org/mailman/listinfo/baypiggies
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20170226/d8e090d6/attachment.html>


More information about the Baypiggies mailing list