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
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
48
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
第3木曜LT会 #28
tinykitten
PRO
0
110
Spec Driven Development | AI Summit Vilnius
danielsogl
PRO
1
110
How Swift's Type System Guides AI Agents
koher
0
310
Claude Code × Gemini × Ebitengine ゲーム制作素人WebエンジニアがGoでゲームを作った話
webzawa
0
160
HTML-Aware ERB: The Path to Reactive Rendering @ RubyKaigi 2026, Hakodate, Japan
marcoroth
0
290
AIエージェントで業務改善してみた
taku271
0
540
ルールルルルルRubyの中身の予備知識 ── RubyKaigiの前に予習しなイカ?
ydah
1
210
Lightning-Fast Method Calls with Ruby 4.1 ZJIT / RubyKaigi 2026
k0kubun
3
1.3k
tRPCの概要と少しだけパフォーマンス
misoton665
2
240
「Linuxサーバー構築標準教科書」を読んでみた #ツナギメオフライン.7
akase244
0
1.4k
TiDBのアーキテクチャから学ぶ分散システム入門 〜MySQL互換のNewSQLは何を解決するのか〜 / tidb-architecture-study
dznbk
1
190
🦞OpenClaw works with AWS
licux
1
270
Featured
See All Featured
Joys of Absence: A Defence of Solitary Play
codingconduct
1
350
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.2k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
70
39k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.4k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.2k
AI: The stuff that nobody shows you
jnunemaker
PRO
6
600
WENDY [Excerpt]
tessaabrams
10
37k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
730
Making Projects Easy
brettharned
120
6.6k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
270
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
10k
Paper Plane (Part 1)
katiecoart
PRO
0
6.8k
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