Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Programe para uma interface, não para uma imple...
Search
Diego Garcia
October 17, 2016
Programming
200
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Programe para uma interface, não para uma implementação
Lightning talk apresentada na Python Brasil 12
Diego Garcia
October 17, 2016
More Decks by Diego Garcia
See All by Diego Garcia
Um overview sobre GIT
drgarcia1986
0
50
Modelos de concorrência e paralelismo em Python
drgarcia1986
0
110
Modelos de concorrência em Python.
drgarcia1986
0
190
Bot do Telegram
drgarcia1986
1
230
Boas práticas em REST APIs
drgarcia1986
1
1.4k
Conteinerizando aplicações Python
drgarcia1986
0
470
Testes de carga com Locust
drgarcia1986
1
460
Other Decks in Programming
See All in Programming
初めてのKubernetes 本番運用でハマった話
oku053
0
130
ルールを書いて終わらせないハーネスエンジニアリング
yug1224
4
1.7k
PHPだって関数型したい 〜できること、できないこと〜 / fp-in-php
jsoizo
1
240
関数型プログラミングのメリットって何だろう?
wanko_it
0
190
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
16
3.6k
act1-costs.pdf
sumedhbala
0
240
吝嗇家のためのAI活用 / AI development for miser - ChatGPT + Issue Driven Development
tooppoo
0
190
音楽のための関数型プログラミング言語mimiumにおける多段階計算の活用
tomoyanonymous
1
350
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
400
SREの積み重ねがAI駆動開発のガードレールになった ― 7つの実践/SRE Guardrails The 7
tomoyakitaura
8
5.1k
LaravelLive Japan の裏方のすべて — 第188回 PHP勉強会@東京 (2026-06-24)
suguruooki
2
150
えっ!!コードを読まずに開発を!?
hananouchi
0
230
Featured
See All Featured
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
880
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
160
Code Review Best Practice
trishagee
74
20k
SEO for Brand Visibility & Recognition
aleyda
0
4.6k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.2k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
490
A Modern Web Designer's Workflow
chriscoyier
698
190k
WCS-LA-2024
lcolladotor
0
740
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
410
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.3k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Transcript
Programe para uma interface, não para uma implementação #pybr12
Quem sou eu?
• Desenvolvedor a ~8 anos. • Desenvolvedor web a ~5
anos. • Pythonista a ~3 anos. • Django, Tornado, Aiohttp, etc. • Vimmer (#vim <3). • Aspirante a Gopher (#Golang <3). • Backend developer at LuizaLabs. Diego Garcia
Programar para uma interface significa se importar com “o que
faz?” e não com o “como faz?”
Exemplo de interface
class Storage: def get(self, key): pass def set(self, key, value):
pass
Exemplo de uso da interface
class Reader: def __init__(self, storage): self.storage = storage def get_info(self):
return self.storage.get('info')
Exemplo de implementação concreta
from redis import StrictRedis class RedisStorage: def __init__(self): self.redis =
StrictRedis() def get(self, key): return self.redis.get(key) def set(self, key, value): self.redis.set(key, value)
• RedisStorage • MemcachedStorage • DatabaseStorage • FileStorage • FakeStorage
• ...
Exemplo de carregamento dinâmico
from importlib import import_module def get_storage_backend(path): module_name, class_name = path.rsplit('.',
1) module = import_module(module_name) backend_class = getattr(module, class_name) return backend_class() storage = get_storage_backend( 'storages.redis.RedisStorage' )
Quem se preocupa com isso? • Django (ORM, Cache, etc).
• Asyncio (EventLoop). • SqlAchemy (Connectors, Engines, etc). • ...
Programar para uma interface já me salvou em uma blackfriday!
Trocamos a API de cálculo de frete só virando uma chave.
Obrigado! Se tiverem perguntas me procurem :) Twitter: @drgarcia1986 |
Github: /drgarcia1986