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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Diego Garcia
October 17, 2016
Programming
200
0
Share
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
220
Boas práticas em REST APIs
drgarcia1986
1
1.4k
Conteinerizando aplicações Python
drgarcia1986
0
460
Testes de carga com Locust
drgarcia1986
1
460
Other Decks in Programming
See All in Programming
ReactとSvelteのその先、Ripple-TS / Beyond React and Svelte: Ripple-TS
ssssota
3
1.8k
Modding RubyKaigi for Myself
yui_knk
0
820
3Dシーンの圧縮
fadis
1
540
ECR拡張スキャンでSBOMを収集して サプライチェーン攻撃の影響調査を 爆速で終わらせてみた
akihisaikeda
2
210
Stage 3 Decorators でできること / できないこと / TSKaigi 2026
susisu
1
1.3k
関係性から理解する"同一性"の型用語たち
pvcresin
2
620
Old Dog, New Tricks: The Java 25 Reinvention - JNation
bazlur_rahman
0
140
Spec-Driven Development with AI-Agents: From High-Level Requirements to Working Software
antonarhipov
2
390
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
2.1k
Composerを使ったサプライチェーン攻撃の様子を眺めてみる #phpstudy
o0h
PRO
2
190
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
220
Moments When Things Go Wrong
aurimas
3
130
Featured
See All Featured
New Earth Scene 8
popppiees
3
2.3k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
160
Evolving SEO for Evolving Search Engines
ryanjones
0
210
The browser strikes back
jonoalderson
0
1.1k
Optimising Largest Contentful Paint
csswizardry
37
3.7k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
61
44k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
180
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
エンジニアに許された特別な時間の終わり
watany
107
240k
Making Projects Easy
brettharned
120
6.7k
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