Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Programe para uma interface, não para uma imple...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
Transcript
16 slides
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
More Decks by Diego Garcia
See All by Diego Garcia
Um overview sobre GIT
drgarcia1986
0
53
Modelos de concorrência e paralelismo em Python
drgarcia1986
0
120
Modelos de concorrência em Python.
drgarcia1986
0
200
Bot do Telegram
drgarcia1986
1
230
Boas práticas em REST APIs
drgarcia1986
1
1.5k
Conteinerizando aplicações Python
drgarcia1986
0
470
Testes de carga com Locust
drgarcia1986
1
470
Other Decks in Programming
See All in Programming
なぜ私たちは「現時点では」KMPの導入を見送ったのか
chigichan24
1
310
将来の標準フォーマッター?ktfmtを深堀る
t45k
0
220
protojson における文字化けの扱い
kazuki1023
0
450
Zero-Tap Sign-In対応、結局何をすればいいの?
mitohato14
0
2.5k
GraphQL の onError と Nullability のこれから
quramy
0
220
Engineering Biometric UX Across Android Versions | DroidKnights 2026
ryunen344
1
220
はじめてのPLATEAU
nokonoko1203
1
660
Snowflake Openflow Connector利用の勘所 / 20261024developersio2026tokyo-snowflake-openflow
kasacchiful
PRO
0
360
Distance field of Julia set
kinakomoti321
0
330
느린 네트워크와 저사양 디바이스 사용자를 위한 웹뷰 로딩 시간 개선기
kmkim
1
260
AI時代のIaC入門 〜なぜインフラをコードで管理したいのか?〜 / Introduction to IaC in the AI Era
akihisaikeda
6
1.6k
AIが実装を担う時代の「技術設計」と「チームマネジメント」
kamina_zzz
2
280
Featured
See All Featured
Abbi's Birthday
coloredviolet
5
11k
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.3k
KATA
mclloyd
PRO
35
16k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
990
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
1k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
320
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.6k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
350
Design in an AI World
tapps
1
390
We Have a Design System, Now What?
morganepeng
55
8.4k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.5k